Reputation: 31
I'm looking to upload some data to an Azure Cloud space. To do so, I use the azure-storage-android library at my disposal. Upload works fine but I'm facing an issue when I'm trying to manage a progress of my upload. I didn't find a pretty solution.
My first idea was this piece of code :
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);
Using this ctxt
object with my upload request. It works but the progress is uploaded every 4MB uploaded (default value), which is problematic as my files have a size around 5-10MB. It creates a progress that is not smooth. I tried to lower that 4MB range size but it actually reduces significantly the upload speed. Why? I'm not sure but I'm guessing there is an authorization process that is being done every X MB instead of 4 which creates latency (once again, I'm not sure, could be something else).
So my question is, is there any efficient way to track progress on upload with the file cloud share service? I thought of using a multipart upload through their REST Api but I have taken a look at their API and I didn't see any indication that this could be done.
Upvotes: 0
Views: 431
Reputation: 24148
I reviewed the source code of Azure Storage SDK for Android, then I found the unit progress is depended on the value of streamWriteSizeInBytes
which be defined in the class CloudFile
and default be equal to Constants.DEFAULT_STREAM_WRITE_IN_BYTES
value that be equal to Constants.MAX_BLOCK_SIZE
value as 4MB.
So if you want to reduce the unit progress size, you can try to use CloudFile.setStreamWriteSizeInBytes(int streamWriteSizeInBytes)
to do it before execute the CloudFile.upload
method.
Hope it helps.
Upvotes: 0