- 浏览: 2552555 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Java and Amazon S3
For S3 client, it should be straightforward, just need to pay attention to 5G file size limitation.
pom.xml as follow:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws.java.sdk.s3.version}</version>
</dependency>
<aws.java.sdk.s3.version>1.11.148</aws.java.sdk.s3.version>
is that the latest version? I do not know, but it is already in my POM.xml
I have a interface which will be shared with S3FileOperation and FtpFileOperation
package com.sillycat.transmission;
public interface Transmission
{
public boolean uploadFile( String bucketName, String key, String fileToUpload );
public boolean downloadFile( String bucketName, String key, String destFolder );
}
The implementation code class is as follow:
package com.sillycat.transmission;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.transfer.Download;
import com.amazonaws.services.s3.transfer.TransferManager;
import com.amazonaws.services.s3.transfer.TransferManagerBuilder;
import com.amazonaws.services.s3.transfer.Upload;
public class TransmissionS3Impl implements Transmission
{
protected final Logger logger = LoggerFactory.getLogger( this.getClass() );
private TransferManager transferManager;
public TransmissionS3Impl()
{
logger.info( "TransmissionS3 start to init the AWS S3 parameters--------" );
String key = System.getProperty( "aws.s3.key" );
String secret = System.getProperty( "aws.s3.secret" );
logger.info( "get aws.s3.key=" + key );
BasicAWSCredentials awsCreds = new BasicAWSCredentials( key, secret );
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials( new AWSStaticCredentialsProvider( awsCreds ) )
.withRegion( Regions.US_EAST_1 ).build();
TransferManager transferManager = TransferManagerBuilder.standard().withS3Client( s3Client ).build();
this.transferManager = transferManager;
logger.info( "TransmissionS3 success init ------------------------------" );
}
@Override
public boolean uploadFile( String bucketName, String key, String fileToUpload )
{
boolean result = false;
logger.debug( "TransmissionS3 upload file bucketName = " + bucketName + " key = " + key + " fileToUpload = "
+ fileToUpload );
try
{
Upload upload = transferManager.upload( bucketName, key, new File( fileToUpload ) );
upload.waitForCompletion();
logger.debug( "TransmissionS3 upload file done." );
result = true;
}
catch ( AmazonClientException | InterruptedException e )
{
logger.error( "AmazonClientException | InterruptedException:", e );
}
return result;
}
@Override
public boolean downloadFile( String bucketName, String key, String destFile )
{
boolean result = false;
logger.debug(
"TransmissionS3 download file bucketName = " + bucketName + " key = " + key + " destFile = " + destFile );
try
{
Download download = transferManager.download( bucketName, key, new File( destFile ) );
download.waitForCompletion();
logger.debug( "TransmissionS3 download file done." );
result = true;
}
catch ( AmazonClientException | InterruptedException e )
{
logger.error( "AmazonClientException | InterruptedException:", e );
}
return result;
}
}
I agree with my colleagues, it will connect to S3, so it should be integration testing, so here is the test class
package com.sillycat.transmission;
import java.io.File;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* how to run: mvn -Dtest=TransmissionS3JUnitIntegrationTest test
* @author carl
*
*/
public class TransmissionS3JUnitIntegrationTest
{
private Transmission transmission;
String bucketName = “sillycat-test";
String key = "developer/test/mock.txt";
@Before
public void setUp() throws Exception
{
System.setProperty( "aws.s3.key", “xxxxxxx" );
System.setProperty( "aws.s3.secret", “xxxxxxxxxxx" );
transmission = new TransmissionS3Impl();
}
@Test
public void uploadFile()
{
String localFilePath = this.getClass().getResource( "mock.txt" ).getPath();
boolean result = transmission.uploadFile( bucketName, key, localFilePath );
Assert.assertTrue( result );
}
@Test
public void downloadFile()
{
String localFilePath = this.getClass().getResource( "mock.txt" ).getPath();
localFilePath = localFilePath.replace( "mock.txt", "mock1.txt" );
boolean result = transmission.downloadFile( bucketName, key, localFilePath );
Assert.assertTrue( result );
Assert.assertTrue( "Download is failing, where is your file.", ( new File( localFilePath ) ).exists() );
}
}
References:
https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/java/example_code/s3/src/main/java/aws/example/s3/XferMgrDownload.java
https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-s3-transfermanager.html#tranfermanager-download-directory
https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/java/example_code/s3/src/main/java/aws/example/s3/XferMgrUpload.java
For S3 client, it should be straightforward, just need to pay attention to 5G file size limitation.
pom.xml as follow:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws.java.sdk.s3.version}</version>
</dependency>
<aws.java.sdk.s3.version>1.11.148</aws.java.sdk.s3.version>
is that the latest version? I do not know, but it is already in my POM.xml
I have a interface which will be shared with S3FileOperation and FtpFileOperation
package com.sillycat.transmission;
public interface Transmission
{
public boolean uploadFile( String bucketName, String key, String fileToUpload );
public boolean downloadFile( String bucketName, String key, String destFolder );
}
The implementation code class is as follow:
package com.sillycat.transmission;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.transfer.Download;
import com.amazonaws.services.s3.transfer.TransferManager;
import com.amazonaws.services.s3.transfer.TransferManagerBuilder;
import com.amazonaws.services.s3.transfer.Upload;
public class TransmissionS3Impl implements Transmission
{
protected final Logger logger = LoggerFactory.getLogger( this.getClass() );
private TransferManager transferManager;
public TransmissionS3Impl()
{
logger.info( "TransmissionS3 start to init the AWS S3 parameters--------" );
String key = System.getProperty( "aws.s3.key" );
String secret = System.getProperty( "aws.s3.secret" );
logger.info( "get aws.s3.key=" + key );
BasicAWSCredentials awsCreds = new BasicAWSCredentials( key, secret );
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials( new AWSStaticCredentialsProvider( awsCreds ) )
.withRegion( Regions.US_EAST_1 ).build();
TransferManager transferManager = TransferManagerBuilder.standard().withS3Client( s3Client ).build();
this.transferManager = transferManager;
logger.info( "TransmissionS3 success init ------------------------------" );
}
@Override
public boolean uploadFile( String bucketName, String key, String fileToUpload )
{
boolean result = false;
logger.debug( "TransmissionS3 upload file bucketName = " + bucketName + " key = " + key + " fileToUpload = "
+ fileToUpload );
try
{
Upload upload = transferManager.upload( bucketName, key, new File( fileToUpload ) );
upload.waitForCompletion();
logger.debug( "TransmissionS3 upload file done." );
result = true;
}
catch ( AmazonClientException | InterruptedException e )
{
logger.error( "AmazonClientException | InterruptedException:", e );
}
return result;
}
@Override
public boolean downloadFile( String bucketName, String key, String destFile )
{
boolean result = false;
logger.debug(
"TransmissionS3 download file bucketName = " + bucketName + " key = " + key + " destFile = " + destFile );
try
{
Download download = transferManager.download( bucketName, key, new File( destFile ) );
download.waitForCompletion();
logger.debug( "TransmissionS3 download file done." );
result = true;
}
catch ( AmazonClientException | InterruptedException e )
{
logger.error( "AmazonClientException | InterruptedException:", e );
}
return result;
}
}
I agree with my colleagues, it will connect to S3, so it should be integration testing, so here is the test class
package com.sillycat.transmission;
import java.io.File;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* how to run: mvn -Dtest=TransmissionS3JUnitIntegrationTest test
* @author carl
*
*/
public class TransmissionS3JUnitIntegrationTest
{
private Transmission transmission;
String bucketName = “sillycat-test";
String key = "developer/test/mock.txt";
@Before
public void setUp() throws Exception
{
System.setProperty( "aws.s3.key", “xxxxxxx" );
System.setProperty( "aws.s3.secret", “xxxxxxxxxxx" );
transmission = new TransmissionS3Impl();
}
@Test
public void uploadFile()
{
String localFilePath = this.getClass().getResource( "mock.txt" ).getPath();
boolean result = transmission.uploadFile( bucketName, key, localFilePath );
Assert.assertTrue( result );
}
@Test
public void downloadFile()
{
String localFilePath = this.getClass().getResource( "mock.txt" ).getPath();
localFilePath = localFilePath.replace( "mock.txt", "mock1.txt" );
boolean result = transmission.downloadFile( bucketName, key, localFilePath );
Assert.assertTrue( result );
Assert.assertTrue( "Download is failing, where is your file.", ( new File( localFilePath ) ).exists() );
}
}
References:
https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/java/example_code/s3/src/main/java/aws/example/s3/XferMgrDownload.java
https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-s3-transfermanager.html#tranfermanager-download-directory
https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/java/example_code/s3/src/main/java/aws/example/s3/XferMgrUpload.java
发表评论
-
Update Site will come soon
2021-06-02 04:10 1679I am still keep notes my tech n ... -
Stop Update Here
2020-04-28 09:00 316I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 476NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 369Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 370Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 337Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 431Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 374Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 456VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 479NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 424Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 248GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 452GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 319Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ...
相关推荐
而Amazon S3(Simple Storage Service)是AWS提供的一个云存储服务,用于存储和检索任何数量的数据,无论何时何地。本篇文章将深入探讨如何在SpringBoot项目中集成AWS S3 SDK(Java V2版本),实现对象的分页列表、...
aws-java-sdk-s3-***.jar中文-英文对照文档.zip,java,aws-java-sdk-s3-***.jar,com.amazonaws,aws-java-sdk-s3,***,com.amazonaws.auth,jar包,Maven,第三方jar包,组件,开源组件,第三方组件,Gradle,amazonaws,aws,sdk...
Amazon Simple Storage Service (S3) 是由亚马逊网络服务 (AWS) 提供的一种面向互联网的对象存储服务,它提供了几乎无限的存储空间。S3 的设计目的是为了支持大规模的数据存储需求,适用于各种场景,包括备份与存档...
Jets3t(Java Toolkit for Amazon S3 and CloudFront)是一个开源的Java库,它为开发者提供了一种简单的方式来与S3进行交互,包括上传、下载、管理对象以及处理权限等操作。本教程旨在帮助新手快速入门S3-jets3t的...
MinIO Java SDK is Simple Storage Service (aka S3) client to perform bucket and object operations to any Amazon S3 compatible object storage service. MinIO Java SDK是简单存储服务(又称S3)的客户端,...
AWS Java SDK 1.2.12 是一个用于与亚马逊Web服务(Amazon Web Services, AWS)进行交互的软件开发工具包,特别适用于Java开发者。这个版本的SDK包含了多个示例项目,可以帮助开发者深入理解如何利用AWS的各项服务。...
《Practical Amazon EC2, SQS, Kinesis, and S3: A Hands-On Approach to AWS-2017》是一本面向实践的指南,旨在帮助读者深入理解和掌握Amazon Web Services (AWS) 中的核心服务,包括Amazon Elastic Compute Cloud ...
在IT行业中,Amazon S3(Simple Storage Service)是亚马逊提供的一种云存储服务,它允许开发者和企业存储和检索大量数据。Blob(Binary Large Object)通常指的是在数据库中存储的二进制大对象,如图像、视频或文档...
- **AWS SDKs**:Amazon提供了多种编程语言的SDK,如Python的boto3、Java的AWS SDK for Java等,这些SDK允许开发者通过源码直接与S3交互,进行对象的修改操作。 - **AWS CLI**:命令行界面工具,可以方便地执行S3...
亚马逊网络服务(Amazon Web Services,简称AWS)是全球领先的云服务提供商,为开发者和企业提供了一系列广泛的服务,包括计算、存储、数据库、分析、机器学习、物联网等。Java作为一门广泛应用的编程语言,与AWS的...
s3_signed_url s3_signed_url生成签名的URL,以获取或放置S3对象。 我们的后端在有描述。 安装 将此行添加到您的应用程序的Gemfile中: gem 's3_signed_url' 然后执行: ...https://s3.amazonaws.co
这个SDK提供了对多种AWS服务的访问,如Amazon S3(简单存储服务)、Amazon EC2(弹性计算云)、DynamoDB(数据库服务)等,通过简洁的API调用来实现这些服务的功能。 **开发工具包版本 2** AWS SDK for Java 版本2...
最后,Amazon IAM(Identity and Access Management)API是管理用户、组和权限的关键工具。通过IAM,开发者可以精细控制谁可以访问哪些AWS资源,以及他们可以执行的操作。这有助于实施安全策略,确保合规性。 综上...
- AWS Mobile SDK:这是一个综合的SDK,包含了多个亚马逊Web服务,如S3(存储服务)、DynamoDB(数据库服务)等,可能用于存储用户偏好或者账户相关数据。 - Login with Amazon:这是亚马逊提供的一种身份服务,允许...
描述中的“Send query to Amazon Web service and returns XML”进一步解释了该工具的主要功能。它执行的是API调用,这在AWS中很常见,因为AWS提供了大量的服务,如S3(Simple Storage Service)、EC2(Elastic ...
亚马逊网络服务(AWS)为移动开发者提供了一套丰富的云服务,以支持iOS和Android等移动平台的应用程序开发。AWS Mobile是AWS中专门为移动应用优化的服务集合,让开发者能利用云基础设施、数据库、消息推送、身份认证...
Apache Spark or Tez or distributed filesystems such as HDFS and Amazon S3 or real-time SQL on underlying data using Impala or Spark SQL. This book provides a lot of information on big data ...
AWS开发SDK是指亚马逊网络服务(Amazon Web Services,简称AWS)推出的软件开发工具包,特别是针对Java语言的版本。AWS是目前全球最大的云服务提供商,提供众多的云服务模块,包括计算、存储、数据库、分析、机器...