Search code examples
androidamazon-s3storageandroid-progressbaraws-amplify

Show progress of file uploads/downloads using the AWS Amplify Storage SDK


I am uploading/downloading files using the Storage API of the AWS Amplify SDK library for Android.

I need to show progress as the operation is going on. Is there any way in the Amplify Storage API to hook a listener or callback such I can listen for upload/download progress, in order to update a progress bar in the UI?

The official documentation does not mention anything for it: https://aws-amplify.github.io/docs/android/storage

If not, I think there are two alternatives:

  • TransferUtility / TransferObserver - It has API to observe progress, but I can't get it to work with Cognito User pools. I don't know if the API allows that.
  • Generate a presigned url in the server, and then use HttpUrlConnection or OkHttp - this would give me access to the underlying InputStream and I could report progress as it's been read, but I find this very low level and I was hoping to be able to delegate into any of the AWS SDKs.

Thank you.


Solution

  • You can use TransferObserver with TransferListener.

    https://aws-amplify.github.io/aws-sdk-android/docs/reference/com/amazonaws/mobileconnectors/s3/transferutility/TransferObserver.html

    It provides you progress of file being transferred.