gpt4 book ai didi

android - AWS s3 TransferListener 未在 Android 中更新

转载 作者:行者123 更新时间:2023-11-30 00:10:30 25 4
gpt4 key购买 nike

我正在尝试从 s3 下载并更新进度条。我设置了 TransferUtility、TransferObserver 和 TransferListener。

问题是,当文件下载时,它很少更新进度。

对于 1.6mb (1665824) 的文件,它将输出 0,然后 30 秒后输出 1050264,然后 30 秒后输出 1665824,然后它自己重复并再次输出 1665824。

所以基本上对用户来说,下载看起来像是被卡住了,或者充其量是不稳定的。

我还尝试将它放入一个循环中并每隔 100 毫秒检查一次值,但它只是在前 30 秒内返回 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) {

}
});

谢谢你的帮助

最佳答案

适用于 Android 的 AWS SDK 2.6.6 版本包含用于修复进度更新问题的修复程序。升级到这个版本应该可以缓解这个问题。
除此之外,您可以调整 AmazonS3ClientnotificationThreshold API 来更改通知进度的间隔。

关于android - AWS s3 TransferListener 未在 Android 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48210469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com