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); // Resumes the transfer. transferUtility.resume(id);For cancelling and deleting tasks:
// Cancels the transfer. transferUtility.cancel(id); // Deletes the transfer. transferUtility.delete(id);
Constructor and Description |
---|
TransferUtility(AmazonS3 s3,
android.content.Context context)
Constructs a new TransferUtility specifying the client to use and
initializes configuration of TransferUtility and a key for S3 client weak
reference.
|
Modifier and Type | Method and Description |
---|---|
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 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.
|
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.
|
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.
|
public TransferUtility(AmazonS3 s3, android.content.Context context)
s3
- The client to use when making requests to Amazon S3context
- The current contextpublic 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 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 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 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 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 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 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 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 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 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 © 2010 Amazon Web Services, Inc. All Rights Reserved.