简体   繁体   中英

Get progress during blob file upload on Azure Android Storage SDK

I'm using this method to upload some files on Blob (some files are large and take several minutes to upload).

    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();
    }
}

As you can see, I use blob.upload() to start uploading the file. Is there any way to get the progress percentage?

Of course, I'm running this method into AsyncTask's doInBackground so it should be easy to update the UI in onProgressUpdate() . I just need to know the progress of the uploading process.

@PaoloRotolo, There is a blog which introduces how to make the process bar with C# in the process of uploading blob. It's very similar with Android in Java. You can try to refer to the sample code of the blog and the javadocs of Azure Storage SDK for Android to write it.

您可以使用blob.CopyState.BytesCopiedblob.CopyState.TotalBytes计算百分比

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM