| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
The AWS SDK for Java provides an API for the Amazon S3 bucket and object operations. For object operations, in addition to providing the API to upload objects in a single operation, the SDK provides API to upload large objects in parts (see Uploading Objects Using Multipart Upload API). The API gives you the option of using a high-level or low-level API.
Low-Level API
The Low-level APIs correspond to the underlying Amazon S3 REST operations, such as create, update, and delete operations that apply to buckets and objects. When you upload large objects using the low-level multipart upload API, it provides greater control such as letting you pause and resume multipart uploads, vary part sizes during the upload, or to begin uploads when you do not know the size of the data in advance. If you do not have these requirements, use the high-level API to upload objects.
High-Level API
For uploading objects, the SDK provides a higher level of abstraction by providing the
TransferManager class. The high-level API is a simpler API, where
in just a few lines of code you can upload files and streams to Amazon S3. You
should use this API to upload data unless you need to control the upload as
described in the preceding Low-Level API section.
For smaller data size the TransferManager API uploads data in a single
operation. However, the TransferManager switches to using the
multipart upload API when data size reaches certain threshold. When possible, the
TransferManager uses multiple threads to concurrently upload
the parts. If a part upload fails, the API retries the failed part upload up to three
times. However, these are configurable options using the
TransferManagerConfiguration class.
Note
When using a stream for the source of data, the TransferManager class
will not do concurrent uploads.
The following packages in the AWS SDK for Java provide the API:
com.amazonaws.services.s3—Provides the implementation APIs for Amazon S3 bucket and object operations.
For example, it provides methods to create buckets, upload objects, get objects, delete objects, and to list keys.
com.amazonaws.services.s3.transfer—Provides the high-level API data upload.
This high-level API is designed to further simplify uploading objects to Amazon S3. It
includes the TransferManager class. It is particularly
useful when uploading large objects in parts. It also include the
TransferManagerConfiguration class which you can
use to configure the minimum part size for uploading parts and the threshold
in bytes of when to use multipart uploads.
com.amazonaws.services.s3.model—Provides the low-level API classes to create requests and process responses.
For example, it includes the GetObjectRequest class to describe
your get object request, the ListObjectRequest class to
describe your list keys requests, and the
InitiateMultipartUploadRequest and
InitiateMultipartUploadResult classes when
initiating a multipart upload.
For more information about the AWS SDK for Java API, go to AWS SDK for Java API Reference.
The easiest way to get started with the Java code examples is to install the latest AWS Toolkit for Eclipse. For information on installing or updating to the latest version, go to http://aws.amazon.com/eclipse. The following tasks guide you through the creation and testing of the Java code samples provided in this section.
General Process of Creating Java Code Examples
1 | Create a new AWS Java project in Eclipse. The project is pre-configured with the AWS SDK for Java and it also includes the AwsCredentials.properties file for your AWS security credentials. |
2 | Copy the code from the section you are reading to your project. |
3 | Update the code by providing any required data. For example, if uploading a file, provide the file path and the bucket name. |
4 | Run the code. Verify that the object is created by using the AWS Management Console. For more information about the AWS Management Console, go to http://aws.amazon.com/console/. |