我正在上传一些数据到Azure云空间。为此,我使用azure-storage-android库供我使用。上传工作正常,但我在尝试管理我的上传进度时遇到问题。我没有找到一个漂亮的解决方案。上传与Azure文件云存储上的进展
我的第一个想法是这一段代码:
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个,这造成了延迟(再次,我不确定,可能是其他)。
所以我的问题是,是否有任何有效的方式来跟踪上传与文件云共享服务的进展?我想通过他们的REST Api使用分段上传,但我看了their API,我没有看到任何迹象表明这可以完成。