2016-08-01 81 views
0

我正在使用此方法上傳Blob上的某些文件(某些文件很大,需要幾分鐘才能上傳)。在Azure Android存儲SDK上的blob文件上傳過程中獲取進度

private void updateFilesOnBlob(){ 
    try { 
     String timestamp = Tools.generateTimeStamp(); 

     // Retrieve storage account from connection-string. 
     CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); 

     // Create the blob client. 
     CloudBlobClient blobClient = storageAccount.createCloudBlobClient(); 

     // Retrieve reference to a previously created container. 
     CloudBlobContainer container = blobClient.getContainerReference(CONTAINER_NAME); 

     // Upload each file on Blob 
     for (int i = 0; i< pathsArrayList.size(); i++) { 
      // Define the path to a local file. 
      final String filePath = pathsArrayList.get(i); 
      CloudBlockBlob blob = container.getBlockBlobReference(timestamp + "/" + filenameFromPath(pathsArrayList.get(i))); 
      File source = new File(filePath); 
      blob.upload(new FileInputStream(source), source.length()); 
     } 
    } 
    catch (Exception e) 
    { 
     // Output the stack trace. 
     e.printStackTrace(); 
    } 
} 

如您所見,我使用blob.upload()開始上傳文件。有沒有辦法獲得進度百分比?

當然,我在AsyncTask的doInBackground中運行此方法,因此應該很容易更新onProgressUpdate()中的UI。我只需要知道上傳過程的進展情況。

回答

0

@PaoloRotolo,有一個blog,介紹如何使C#的過程中吧上傳Blob的過程。它與Java中的Android非常相似。您可以嘗試參考博客的示例代碼以及適用於Android的Azure存儲SDK的javadocs以編寫它。

相關問題