简体   繁体   English

我如何获得amazon多文件上传s3 android的进度条

[英]How can i get progress bar for amazon multiple file upload s3 android

now am using MultipleFileUpload method .how can i get progress bar for that .please some help me. 现在我正在使用MultipleFileUpload方法。我可以获得进度条。请帮助我。

 MultipleFileUpload upload = tm.uploadFileList(
            "backetname", s3_path, myDir_temp, collection_file, metadataProvider);

Use the AWS SDK for Android and Check the AWS docs for the same: https://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/s3transferutility.html 使用AWS SDK for Android并检查AWS文档: https//docs.aws.amazon.com/mobile/sdkforandroid/developerguide/s3transferutility.html

With the Transfer Utility, the download() and upload() methods return a TransferObserver object. 使用Transfer Utility,download()和upload()方法返回TransferObserver对象。 This object gives access to: 该对象提供访问:

The state (now specified as an enum) The total bytes transferred thus far The total bytes to transfer (for easily calculating progress bars) A unique ID that you can use to keep track of distinct transfers Given the transfer ID, this TransferObserver object can be retrieved from anywhere in your app, including if the app is killed. 状态(现在指定为枚举)到目前为止传输的总字节数要传输的总字节数(用于轻松计算进度条)可用于跟踪不同传输的唯一ID给定传输ID,此TransferObserver对象可以是从应用中的任何位置检索,包括应用是否被杀死。 It also lets you create a TransferListener, which will be updated on state or progress change, as well as when an error occurs. 它还允许您创建TransferListener,它将在状态或进度更改时以及发生错误时更新。

To get the progress of a download or upload, call setTransferListener() on your TransferObserver. 要获得下载或上载的进度,请在TransferObserver上调用setTransferListener()。 This requires you to implement onStateChanged, onProgressChanged, and onError. 这需要您实现onStateChanged,onProgressChanged和onError。 For example: 例如:

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 transfered to user
    }

    @Override
    public void onError(int id, Exception ex) {
        // do something
    }

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM