You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TransferObservertransferObserver = download(MY_BUCKET, OBJECT_KEY, MY_FILE);
transferObserver.setTransferListener(newTransferListener(){
@OverridepublicvoidonStateChanged(intid, TransferStatestate) {
// do something
}
@OverridepublicvoidonProgressChanged(intid, longbytesCurrent, longbytesTotal) {
intpercentage = (int) (bytesCurrent/bytesTotal * 100);
//Display percentage transferred to user
}
@OverridepublicvoidonError(intid, Exceptionex) {
// do something
}
});
TransferUtility also provides methods : resume( id ), cancel ( id ), pause( id )
The id (transfer ID) can be retrieved from the TransferObserver object that is returned from the upload or download function.
Encountered states on Amplify StorageHub Channel :
COMPLETED
This state represents a transfer that is completed
IN_PROGRESS
This state represents a transfer that is currently uploading or downloading data
WAITING_FOR_NETWORK
This state represents a transfer that is currently on hold, waiting for the network to become available
While using Amplify SDK, we don't have access to TransferUtility and can't set our own TransferListener for TransferObserver
Default TransferListener used by Amplify is :
privatefinalclassDownloadTransferListenerimplementsTransferListener {
@OverridepublicvoidonStateChanged(inttransferId, TransferStatestate) {
Amplify.Hub.publish(HubChannel.STORAGE,
HubEvent.create(StorageChannelEventName.DOWNLOAD_STATE, state.name()));
switch (state) {
caseCOMPLETED:
onSuccess.accept(StorageDownloadFileResult.fromFile(file));
return;
caseFAILED:
// no-op;default:
// no-op;
}
}
@OverridepublicvoidonProgressChanged(inttransferId, longbytesCurrent, longbytesTotal) {
onProgress.accept(newStorageTransferProgress(bytesCurrent, bytesTotal));
}
@OverridepublicvoidonError(inttransferId, Exceptionexception) {
Amplify.Hub.publish(HubChannel.STORAGE,
HubEvent.create(StorageChannelEventName.DOWNLOAD_ERROR, exception));
onError.accept(newStorageException(
"Something went wrong with your AWS S3 Storage download file operation",
exception,
"See attached exception for more information and suggestions"
));
}
}
So, How can we get the update to states?
In Amplify's DownloadTransferListener above, on every state change it publishes current state to Amplify.Hub <HubChannel.STORAGE> and by subscribing to it we can get the flow of current states (but can't uniquely identify the download task)
Tracking Download Progress:
1.How Transfer Utility works at Low Level ?:
Every call to download(key, localFile) returns a TransferObserver object to later identify this download task.
To get the progress of a transfer, we've to set TransferListener() implementing onStateChanged, onProgressChanged, and onErrorfor for every TransferObserver:
https://docs.amplify.aws/sdk/storage/transfer-utility/q/platform/android#track-transfer-progress
TransferUtility also provides methods : resume( id ), cancel ( id ), pause( id )
The id (transfer ID) can be retrieved from the TransferObserver object that is returned from the upload or download function.
Value of TransferState gives the status of a download task, possible states are:
All Possible TransferState - Doc
All Possible TransferState - Java File
Encountered states on Amplify StorageHub Channel :
This state represents a transfer that is completed
This state represents a transfer that is currently uploading or downloading data
This state represents a transfer that is currently on hold, waiting for the network to become available
While using Amplify SDK, we don't have access to TransferUtility and can't set our own TransferListener for TransferObserver
Default TransferListener used by Amplify is :
So, How can we get the update to states?
In Amplify's DownloadTransferListener above, on every state change it publishes current state to Amplify.Hub
<HubChannel.STORAGE>
and by subscribing to it we can get the flow of current states (but can't uniquely identify the download task)More Details on internal working of TransferUtililty - archived Java Files:
TransferNetworkLossHandler.java gives status of network
TransferDBUtil.java maintains database of all transfers
DownloadTask.java uses TransferNetworkLossHandler.java & TransferDBUtil.java to automatically pause or resume download
More archived links of aws-sdk (not Amplify)
*Android Transfer Utility Sample (aws-sdk-android)
*Introducing the Transfer Utility for the AWS SDK for Android
*AWS SDK for Android Transfer Manager to Transfer Utility Migration Guide
*Using the S3 Transfer Utility
The text was updated successfully, but these errors were encountered: