![](/img/trans.png)
[英]Get progress during blob file upload on Azure Android Storage SDK
[英]Upload With Progress on Azure File Cloud Storage
我想将一些数据上传到Azure云空间。 为此,我可以使用azure-storage-android库。 上传效果很好,但是在尝试管理上传进度时遇到问题。 我没有找到一个很好的解决方案。
我的第一个想法是这段代码:
OperationContext ctxt = new OperationContext();
ctxt.getRequestCompletedEventHandler().addListener(new StorageEvent<RequestCompletedEvent>() {
@Override
public void eventOccurred(RequestCompletedEvent eventArg) {
totalUploaded = totalUploaded+rangeInBytes;
int progressPercentage = (int) ((float)totalUploaded / (float) totalLength * 100);
//range is 4Mb, totalUploaded and totalLength are initialized higher in the method.
//here, insert a callback to display the progress
publishProgress(progressPercentage);
}
});
destinationFile.upload(new FileInputStream(file),file.length(),null,null,ctxt);
将此ctxt
对象与我的上传请求一起使用。 它可以工作,但是每上传4MB就会上传进度(默认值),这是有问题的,因为我的文件大小约为5-10MB。 这会导致进度不顺利。 我试图减小4MB的范围大小,但实际上大大降低了上传速度。 为什么? 我不确定,但是我猜每个X MB都会执行一个授权过程,而不是每个4 MB,这会造成延迟(再次,我不确定,可能是其他原因)。
所以我的问题是,是否有任何有效的方法来跟踪文件云共享服务上载的进度? 我曾考虑过通过他们的REST Api使用分段上传,但是我看了看他们的API ,但没有看到任何迹象表明可以做到这一点。
我审查Azure存储SDK为Android的源代码,然后我发现单元进展依赖于的值streamWriteSizeInBytes
这在类中定义CloudFile
和默认等于Constants.DEFAULT_STREAM_WRITE_IN_BYTES
值,该值等于Constants.MAX_BLOCK_SIZE
值作为4MB。
因此,如果要减小单元进度大小,可以在执行CloudFile.upload
方法之前尝试使用CloudFile.setStreamWriteSizeInBytes(int streamWriteSizeInBytes)
来执行此CloudFile.upload
。
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.