0

By Using Java SDK of Azure blob storage, Is there a way to download a large file from Azure blob storage with resume functionality?

Harikrishnan
  • 3,664
  • 7
  • 48
  • 77
  • Have you tried anything so far? – Jay Modi Mar 18 '19 at 06:26
  • I am new to Azure, I have tried BlockBlobURL.download method to download chunks and it works perfectly. But this is not satisfying my one use case is that it can not resume download when an error occurs during downloading. – Rajan Patidar Mar 18 '19 at 06:30
  • @RajanPatidar What version of Azure Stoarge SDK for Java you used now? – Peter Pan Mar 18 '19 at 07:11

1 Answers1

2

Absolutely yes. According to the reference of Azure REST API Get Blob for Stoage Service, there is a parameter x-ms-range of request headers for downloading the part of Blob.

x-ms-range

Optional. Return only the bytes of the blob in the specified range. If both Range and x-ms-range are specified, the service uses the value of x-ms-range. If neither are specified, the entire blob contents are returned. See Specifying the Range Header for Blob Service Operations for more information.

So you can resume the downloading process by pass the x-ms-range value with bytes=<the byte size of your downloaded>- to continous to download the full tail of a blob in a working thread.

Or considering for the performance, you can first to get the byte size of a blob, and then to use x-ms-range to download the slices of a blob separately in multiple working threads and concat the blob slices to a completed one.

In Azure Storage for Java v8(Legacy), directly to use the downloadRange method of CloudBlob with parameter offset and length(it equals x-ms-range: <offset>-<offset+length>).

In Azure Storage for Java v10, to pass a BlobRange object to the download method of BlobURL.

Community
  • 1
  • 1
Peter Pan
  • 23,476
  • 4
  • 25
  • 43