我正在使用此方法上傳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。我只需要知道上傳過程的進展情況。