2017-08-03 57 views
0

我正在上傳一些數據到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,我沒有看到任何跡象表明這可以完成。

回答

相關問題