【发布时间】:2018-06-20 23:36:40
【问题描述】:
我正在尝试从 s3 下载并更新进度条。我设置了 TransferUtility、TransferObserver 和 TransferListener。
问题在于,随着文件的下载,它很少更新进度。
对于 1.6mb (1665824) 的文件,它将输出 0,然后 30 秒后输出 1050264,然后 30 秒后输出 1665824,然后它会重复自身并再次输出 1665824。
所以基本上对于用户来说,下载看起来像是被冻结或充其量是生涩的。
我也尝试将它放入一个循环中并检查每 100 毫秒的值,但它只是在前 3 秒内返回 0,就像侦听器一样。
这就是我的实现方式:
// Create s3 client and set region and endpoints
AmazonS3Client s3Client = new AmazonS3Client(IdentityManager.getDefaultIdentityManager().getCredentialsProvider(), new ClientConfiguration());
s3Client.setRegion(Region.getRegion(Regions.US_EAST_1));
// Create a tranfer utility and attach to s3 client
TransferUtility transferUtility = TransferUtility.builder().s3Client(s3Client).context(getActivity()).build();
// String key for the file to download
String key = "ExampleVideo.mp4";
// Location to download files from S3
File file = new File(Environment.getExternalStorageDirectory().toString() + "/" + key);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
// Bucket that contains the file to download
String bucket = "My_Bucket";
// Create a tranfer observer to download
TransferObserver observer = transferUtility.download(bucket,key,file);
// Attach listener to the download to listen for changes in the the download process
observer.setTransferListener(new TransferListener() {
@Override
public void onStateChanged(int id, TransferState state) {
}
@Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
}
@Override
public void onError(int id, Exception ex) {
}
});
感谢您的帮助
【问题讨论】:
-
你是否在清单中添加了
<service android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService" android:enabled="true" />标签? -
感谢您的评论。是的,我有它,如果我没有,它根本不起作用
-
嗯,没错。我认为这是一个已知问题,看看这个link。我面临一个类似的问题,在快速互联网传输监听器上显示 0%、10%,然后直接显示为 100%
-
您使用的是什么版本的 SDK?我们通过在 2.6.6 (github.com/aws/aws-sdk-android/blob/master/…) 中配置通知阈值来解决此问题。您可以尝试使用 >= 2.6.6 版本,看看是否可以缓解问题?谢谢!
-
除此之外,您还可以调整
notificationThresholdAPI 以更改通知进度的间隔。
标签: android amazon-web-services amazon-s3 awss3transferutility