【发布时间】:2016-12-07 00:52:24
【问题描述】:
我正在使用这种方法在 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 应该很容易。我只需要知道上传过程的进度。
【问题讨论】:
标签: java android azure android-asynctask azure-blob-storage