Azure 在 JAVA 中以暂停恢复功能分块下载大块

Azure Download Large Block in chunks with pause resume functionality in JAVA

通过使用 Azure blob 存储的 Java SDK,有没有办法从具有恢复功能的 Azure blob 存储下载大文件?

绝对是的。根据 Azure REST API Get Blob for Stoage Service 的参考,有一个参数 x-ms-range of request headers for downloading 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.

因此,您可以通过将 x-ms-range 值与 bytes=<the byte size of your downloaded>- 一起传递来恢复下载过程,以继续在工作线程中下载 blob 的完整尾部。

或者考虑到性能,可以先获取blob的字节大小,然后使用x-ms-range在多个工作线程中分别下载blob的切片并将blob切片拼接成一个完成的。

在 Java v8(Legacy) 的 Azure 存储中,直接使用 CloudBlobdownloadRange 方法,参数为 offsetlength(it等于 x-ms-range: <offset>-<offset+length>).

在 Java v10 的 Azure 存储中,传递 BlobURLBlobRange object to the download 方法。