Is there a way to specify the maximum number of retires to "downloadToFile" method (also to "upload" method) in com.microsoft.azure.storage.blob.CloudBlockBlob? Or do we have to implement a max number of retries logic if we are calling that method? or is there any way that Azure SDK for Java implements max retires? I saw this article: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-retry-policy But it is for .NET SDK. How to implement it in Java SDK?
CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient serviceClient = account.createCloudBlobClient();
// Container name must be lower case.
CloudBlobContainer container = serviceClient.getContainerReference("container-name");
container.createIfNotExists();
// Upload a file.
CloudBlockBlob blob = container.getBlockBlobReference("demo.txt");
File sourceFile = new File("/path/to/file/demo.txt");
try (FileInputStream sourceStream = new FileInputStream(sourceFile)) {
blob.upload(sourceStream, sourceFile.length());
}
`
Note: dependency and its version I'm using are:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.6.6</version>
</dependency>
I tried in my environment and got the below results:
You can use the below code for attempts to
uploada blob with retries using a while loop that continues until either the operation succeeds or the maximum number of retries is reached. If a StorageException is thrown, indicating a failure, the code waits for a specified interval before attempting the operation again.Code:
Output:
Portal:
For download a blob with max tries, you can use the below code:
Code:
Output:
file: