Git Product home page Git Product logo

git-cousera's People

Contributors

somnaths09 avatar

Watchers

 avatar

git-cousera's Issues

About Downloading

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

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 :

  1. COMPLETED
    This state represents a transfer that is completed
  2. IN_PROGRESS
    This state represents a transfer that is currently uploading or downloading data
  3. 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 :

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.