aws s3 java使用教程_Amazon AWS S3 操作手册

Install the SDK

The recommended way to use the AWS SDK for Java in your project is to consume it from Maven. Import the aws-java-sdk-bom and specify the SDK Maven modules that your project needs in the dependencies.

Importing the BOM

com.amazonaws

aws-java-sdk-bom

1.11.63

pom

import

Using the SDK Maven modules

com.amazonaws

aws-java-sdk-ec2

com.amazonaws

aws-java-sdk-s3

com.amazonaws

aws-java-sdk-dynamodb

See the Set up the AWS SDK for Javasection of the developer guide for more information about installing the SDK through other means.

Features

Provides easy-to-use HTTP clients for all supported AWS services, regions, and authentication protocols.

Client-Side Data Encryption for Amazon S3 - Helps improve the security of storing application data in Amazon S3.

Amazon DynamoDB Object Mapper - Uses Plain Old Java Object (POJOs) to store and retrieve Amazon DynamoDB data.

Amazon S3 Transfer Manager - With a simple API, achieve enhanced the throughput, performance, and reliability by using multi-threaded Amazon S3 multipart calls.

Amazon SQS Client-Side Buffering - Collect and send SQS requests in asynchronous batches, improving application and network performance.

Automatically uses IAM Instance Profile Credentials on configured Amazon EC2 instances.

And more!

Building From Source

Once you check out the code from GitHub, you can build it using Maven. To disable the GPG-signing in the build, use:

mvn clean install -Dgpg.skip=true

Supported Versions

1.11.x - Recommended.

1.10.x - Approved. Only major critical bugs will be fixed. To get the new features, upgrade to 1.11.x version of the SDK.

https://github.com/helloworldtang/aws-sdk-java

/** Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.

*

* Licensed under the Apache License, Version 2.0 (the "License").

* You may not use this file except in compliance with the License.

* A copy of the License is located at

*

*http://aws.amazon.com/apache2.0*

* or in the "license" file accompanying this file. This file is distributed

* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either

* express or implied. See the License for the specific language governing

* permissions and limitations under the License.*/

importjava.io.BufferedReader;importjava.io.File;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.io.OutputStreamWriter;importjava.io.Writer;importjava.util.UUID;importcom.amazonaws.AmazonClientException;importcom.amazonaws.AmazonServiceException;importcom.amazonaws.auth.AWSCredentials;importcom.amazonaws.auth.profile.ProfileCredentialsProvider;importcom.amazonaws.regions.Region;importcom.amazonaws.regions.Regions;importcom.amazonaws.services.s3.AmazonS3;importcom.amazonaws.services.s3.AmazonS3Client;importcom.amazonaws.services.s3.model.Bucket;importcom.amazonaws.services.s3.model.GetObjectRequest;importcom.amazonaws.services.s3.model.ListObjectsRequest;importcom.amazonaws.services.s3.model.ObjectListing;importcom.amazonaws.services.s3.model.PutObjectRequest;importcom.amazonaws.services.s3.model.S3Object;importcom.amazonaws.services.s3.model.S3ObjectSummary;/*** This sample demonstrates how to make basic requests to Amazon S3 using the

* AWS SDK for Java.

*

* Prerequisites: You must have a valid Amazon Web Services developer

* account, and be signed up to use Amazon S3. For more information on Amazon

* S3, seehttp://aws.amazon.com/s3.*

* Fill in your AWS access credentials in the provided credentials file

* template, and be sure to move the file to the default location

* (~/.aws/credentials) where the sample code will load the credentials from.

*

* WARNING: To avoid accidental leakage of your credentials, DO NOT keep

* the credentials file in your source directory.

*

*http://aws.amazon.com/security-credentials

*/

public classS3Sample {public static void main(String[] args) throwsIOException {/** The ProfileCredentialsProvider will return your [default]

* credential profile by reading from the credentials file located at

* (~/.aws/credentials).*/AWSCredentials credentials= null;try{

credentials= newProfileCredentialsProvider().getCredentials();

}catch(Exception e) {throw newAmazonClientException("Cannot load the credentials from the credential profiles file. " +

"Please make sure that your credentials file is at the correct " +

"location (~/.aws/credentials), and is in valid format.",

e);

}

AmazonS3 s3= newAmazonS3Client(credentials);

Region usWest2=Region.getRegion(Regions.US_WEST_2);

s3.setRegion(usWest2);

String bucketName= "my-first-s3-bucket-" +UUID.randomUUID();

String key= "MyObjectKey";//key可以以目录的形式出现a/b,则会在a目录下创建b文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值