public class TransferUtility
extends java.lang.Object
// Initializes TransferUtility TransferUtility transferUtility = new TransferUtility(s3, getApplicationContext()); // Starts a download TransferObserver observer = transferUtility.download("bucket_name", "key", file); observer.setTransferListener(new TransferListener() { public void onStateChanged(int id, String newState) { // Do something in the callback. } public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) { // Do something in the callback. } public void onError(int id, Exception e) { // Do something in the callback. } });For pausing and resuming tasks:
// Gets id of the transfer. int id = observer.getId(); // Pauses the transfer. transferUtility.pause(id); // Pause all the transfers. transferUtility.pauseAllWithType(TransferType.ANY); // Resumes the transfer. transferUtility.resume(id); // Resume all the transfers. transferUtility.resumeAllWithType(TransferType.ANY);For canceling and deleting tasks:
// Cancels the transfer. transferUtility.cancel(id); // Cancel all the transfers. transferUtility.cancelAllWithType(TransferType.ANY); // Deletes the transfer. transferUtility.delete(id);
Modifier and Type | Class and Description |
---|---|
static class |
TransferUtility.Builder
Builder class for TransferUtility
|
Constructor and Description |
---|
TransferUtility(AmazonS3 s3,
android.content.Context context)
Deprecated.
Please use
TransferUtility.builder().s3Client(s3).context(context).build()
|
Modifier and Type | Method and Description |
---|---|
static TransferUtility.Builder |
builder()
Minimum calls required.
|
boolean |
cancel(int id)
Sets a transfer to be canceled.
|
void |
cancelAllWithType(TransferType type)
Sets all transfers which have the given type to be canceled.
|
boolean |
deleteTransferRecord(int id)
Deletes a transfer record with the given id.
|
TransferObserver |
download(java.lang.String key,
java.io.File file)
Starts downloading the S3 object specified by the default bucket and
the key to the given file.
|
TransferObserver |
download(java.lang.String key,
java.io.File file,
TransferListener listener)
Starts downloading the S3 object specified by the default bucket and
the key to the given file.
|
TransferObserver |
download(java.lang.String bucket,
java.lang.String key,
java.io.File file)
Starts downloading the S3 object specified by the bucket and the key to the
given file.
|
TransferObserver |
download(java.lang.String bucket,
java.lang.String key,
java.io.File file,
TransferListener listener)
Starts downloading the S3 object specified by the bucket and the key to the
given file.
|
TransferObserver |
getTransferById(int id)
Gets a TransferObserver instance to track the record with the given id.
|
java.util.List<TransferObserver> |
getTransfersWithType(TransferType type)
Gets a list of TransferObserver instances which are observing records with
the given type.
|
java.util.List<TransferObserver> |
getTransfersWithTypeAndState(TransferType type,
TransferState state)
Gets a list of TransferObserver instances which are observing records with
the given type.
|
java.util.List<TransferObserver> |
getTransfersWithTypeAndStates(TransferType type,
TransferState[] states)
Gets a list of TransferObserver instances which are observing records with
the given type.
|
boolean |
pause(int id)
Pauses a transfer task with the given id.
|
void |
pauseAllWithType(TransferType type)
Pauses all transfers which have the given type.
|
TransferObserver |
resume(int id)
Resumes the transfer task with the given id.
|
java.util.List<TransferObserver> |
resumeAllWithType(TransferType type)
Resume all the transfers which are not finished.
|
TransferObserver |
upload(java.lang.String key,
java.io.File file)
Starts uploading the file to the default bucket, using the given key.
|
TransferObserver |
upload(java.lang.String key,
java.io.File file,
CannedAccessControlList cannedAcl)
Starts uploading the file to the default bucket, using the given key.
|
TransferObserver |
upload(java.lang.String key,
java.io.File file,
ObjectMetadata metadata)
Starts uploading the file to the default bucket, using the given key.
|
TransferObserver |
upload(java.lang.String key,
java.io.File file,
ObjectMetadata metadata,
CannedAccessControlList cannedAcl)
Starts uploading the file to the default bucket, using the given key.
|
TransferObserver |
upload(java.lang.String key,
java.io.File file,
ObjectMetadata metadata,
CannedAccessControlList cannedAcl,
TransferListener listener)
Starts uploading the file to the default bucket, using the given key.
|
TransferObserver |
upload(java.lang.String key,
java.io.InputStream inputStream)
Starts uploading the inputStream to the default bucket, using the given key.
|
TransferObserver |
upload(java.lang.String key,
java.io.InputStream inputStream,
UploadOptions options)
Starts uploading the inputStream to the given bucket, using the given key.
|
TransferObserver |
upload(java.lang.String bucket,
java.lang.String key,
java.io.File file)
Starts uploading the file to the given bucket, using the given key.
|
TransferObserver |
upload(java.lang.String bucket,
java.lang.String key,
java.io.File file,
CannedAccessControlList cannedAcl)
Starts uploading the file to the given bucket, using the given key.
|
TransferObserver |
upload(java.lang.String bucket,
java.lang.String key,
java.io.File file,
ObjectMetadata metadata)
Starts uploading the file to the given bucket, using the given key.
|
TransferObserver |
upload(java.lang.String bucket,
java.lang.String key,
java.io.File file,
ObjectMetadata metadata,
CannedAccessControlList cannedAcl)
Starts uploading the file to the given bucket, using the given key.
|
TransferObserver |
upload(java.lang.String bucket,
java.lang.String key,
java.io.File file,
ObjectMetadata metadata,
CannedAccessControlList cannedAcl,
TransferListener listener)
Starts uploading the file to the given bucket, using the given key.
|
@Deprecated public TransferUtility(AmazonS3 s3, android.content.Context context)
s3
- The client to use when making requests to Amazon S3context
- The current contextpublic static TransferUtility.Builder builder()
public TransferObserver download(java.lang.String bucket, java.lang.String key, java.io.File file)
bucket
- The name of the bucket containing the object to download.key
- The key under which the object to download is stored.file
- The file to download the object's data to.public TransferObserver download(java.lang.String key, java.io.File file)
key
- The key under which the object to download is stored.file
- The file to download the object's data to.public TransferObserver download(java.lang.String bucket, java.lang.String key, java.io.File file, TransferListener listener)
bucket
- The name of the bucket containing the object to download.key
- The key under which the object to download is stored.file
- The file to download the object's data to.listener
- a listener to attach to transfer observer.public TransferObserver download(java.lang.String key, java.io.File file, TransferListener listener)
key
- The key under which the object to download is stored.file
- The file to download the object's data to.listener
- a listener to attach to transfer observer.public TransferObserver upload(java.lang.String bucket, java.lang.String key, java.io.File file)
bucket
- The name of the bucket to upload the new object to.key
- The key in the specified bucket by which to store the new
object.file
- The file to upload.public TransferObserver upload(java.lang.String key, java.io.File file)
key
- The key in the specified bucket by which to store the new object.file
- The file to upload.public TransferObserver upload(java.lang.String bucket, java.lang.String key, java.io.File file, CannedAccessControlList cannedAcl)
bucket
- The name of the bucket to upload the new object to.key
- The key in the specified bucket by which to store the new
object.file
- The file to upload.cannedAcl
- The canned ACL to associate with this objectpublic TransferObserver upload(java.lang.String key, java.io.File file, CannedAccessControlList cannedAcl)
key
- The key in the specified bucket by which to store the new
object.file
- The file to upload.cannedAcl
- The canned ACL to associate with this objectpublic TransferObserver upload(java.lang.String bucket, java.lang.String key, java.io.File file, ObjectMetadata metadata)
bucket
- The name of the bucket to upload the new object to.key
- The key in the specified bucket by which to store the new
object.file
- The file to upload.metadata
- The S3 metadata to associate with this objectpublic TransferObserver upload(java.lang.String key, java.io.File file, ObjectMetadata metadata)
key
- The key in the specified bucket by which to store the new
object.file
- The file to upload.metadata
- The S3 metadata to associate with this objectpublic TransferObserver upload(java.lang.String bucket, java.lang.String key, java.io.File file, ObjectMetadata metadata, CannedAccessControlList cannedAcl)
bucket
- The name of the bucket to upload the new object to.key
- The key in the specified bucket by which to store the new
object.file
- The file to upload.metadata
- The S3 metadata to associate with this objectcannedAcl
- The canned ACL to associate with this objectpublic TransferObserver upload(java.lang.String key, java.io.File file, ObjectMetadata metadata, CannedAccessControlList cannedAcl)
key
- The key in the specified bucket by which to store the new
object.file
- The file to upload.metadata
- The S3 metadata to associate with this objectcannedAcl
- The canned ACL to associate with this objectpublic TransferObserver upload(java.lang.String bucket, java.lang.String key, java.io.File file, ObjectMetadata metadata, CannedAccessControlList cannedAcl, TransferListener listener)
bucket
- The name of the bucket to upload the new object to.key
- The key in the specified bucket by which to store the new
object.file
- The file to upload.metadata
- The S3 metadata to associate with this objectcannedAcl
- The canned ACL to associate with this objectlistener
- a listener to attach to transfer observer.public TransferObserver upload(java.lang.String key, java.io.File file, ObjectMetadata metadata, CannedAccessControlList cannedAcl, TransferListener listener)
key
- The key in the specified bucket by which to store the new
object.file
- The file to upload.metadata
- The S3 metadata to associate with this objectcannedAcl
- The canned ACL to associate with this objectlistener
- a listener to attach to transfer observer.public TransferObserver upload(java.lang.String key, java.io.InputStream inputStream) throws java.io.IOException
key
- The key in the specified bucket by which to store the new object.inputStream
- The input stream to upload.java.io.IOException
public TransferObserver upload(java.lang.String key, java.io.InputStream inputStream, UploadOptions options) throws java.io.IOException
key
- The key in the specified bucket by which to store the new object.inputStream
- The input stream to upload.options
- An UploadOptions which hold all of the optional parameters
i.e. bucket, metadata, cannedAcl and transferListener.java.io.IOException
public TransferObserver getTransferById(int id)
id
- A transfer id.public java.util.List<TransferObserver> getTransfersWithType(TransferType type)
type
- The type of the transfer "any".public java.util.List<TransferObserver> getTransfersWithTypeAndState(TransferType type, TransferState state)
type
- The type of the transfer.state
- The state of the transfer.public java.util.List<TransferObserver> getTransfersWithTypeAndStates(TransferType type, TransferState[] states)
type
- The type of the transfer.states
- A list of the the transfer states.public boolean pause(int id)
id
- A transfer id specifying the transfer to be pausedpublic void pauseAllWithType(TransferType type)
type
- The type of transferspublic TransferObserver resume(int id)
id
- A transfer id specifying the transfer to be resumedpublic java.util.List<TransferObserver> resumeAllWithType(TransferType type)
type
- The type of transferspublic boolean cancel(int id)
id
- A transfer id specifying the transfer to be canceledpublic void cancelAllWithType(TransferType type)
type
- The type of transferspublic boolean deleteTransferRecord(int id)
id
- A transfer id specifying the transfer to be deleted.Copyright © 2018 Amazon Web Services, Inc. All Rights Reserved.