somnaths09 / git-cousera Goto Github PK
View Code? Open in Web Editor NEWGit-Cousera
Git-Cousera
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
TransferObserver transferObserver = download(MY_BUCKET, OBJECT_KEY, MY_FILE);
transferObserver.setTransferListener(new TransferListener(){
@Override
public void onStateChanged(int id, TransferState state) {
// do something
}
@Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
int percentage = (int) (bytesCurrent/bytesTotal * 100);
//Display percentage transferred to user
}
@Override
public void onError(int id, Exception ex) {
// 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.
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 :
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 :
private final class DownloadTransferListener implements TransferListener {
@Override
public void onStateChanged(int transferId, TransferState state) {
Amplify.Hub.publish(HubChannel.STORAGE,
HubEvent.create(StorageChannelEventName.DOWNLOAD_STATE, state.name()));
switch (state) {
case COMPLETED:
onSuccess.accept(StorageDownloadFileResult.fromFile(file));
return;
case FAILED:
// no-op;
default:
// no-op;
}
}
@Override
public void onProgressChanged(int transferId, long bytesCurrent, long bytesTotal) {
onProgress.accept(new StorageTransferProgress(bytesCurrent, bytesTotal));
}
@Override
public void onError(int transferId, Exception exception) {
Amplify.Hub.publish(HubChannel.STORAGE,
HubEvent.create(StorageChannelEventName.DOWNLOAD_ERROR, exception));
onError.accept(new StorageException(
"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)
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.