public class TransferUtility extends 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(String bucket,
String key,
File file)
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.
|
List<TransferObserver> |
getTransfersWithType(TransferType type)
Gets a list of TransferObserver instances which are observing records
with the given type.
|
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(String bucket,
String key,
File file)
Starts uploading the file to the given bucket, using the given key.
|
TransferObserver |
upload(String bucket,
String key,
File file,
ObjectMetadata metadata)
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 contextconfiguration - Configuration parameters for this TransferUtilitypublic TransferObserver download(String bucket, String key, 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 upload(String bucket, String key, 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(String bucket, String key, 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 getTransferById(int id)
id - A transfer id.public List<TransferObserver> getTransfersWithType(TransferType type)
type - The type of the transfer "any".public 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 © 2016. All rights reserved.