从 Azure 存储下载部分文件
Download partial file from Azure storage
我的文件很大。由于文件太大,我一直在尝试从 Azure blob 存储下载部分文件。
我一直在使用 class CloudBlockBlob
中的 DownloadRangeToStream
方法,它对我来说非常好用。
现在我们计划使用 Azure.Storage.Blobs.Specialized.BlockBlobClient
上传,BlockBlobClient
class 中没有类似的方法下载范围或 blob 块中的文件(不是整个文件,而是一个它的块)
我想知道是否有任何其他方法可以更优化地做同样的事情。!!
检查 class BlockBlobClient. To perform a partial update of the content of a block blob, use the StageBlock(String, Stream, Byte[], BlobRequestConditions, IProgress, CancellationToken) and CommitBlockList(IEnumerable, BlobHttpHeaders, IDictionary<String,String>, BlobRequestConditions, Nullable, CancellationToken) 操作的详细信息。
希望对您有所帮助。
您要使用的方法是 Download(HttpRange, BlobRequestConditions, Boolean, CancellationToken)
which is in BlobBaseClient
class(BlockBlobClient 派生自此 class)。
HttpRange
此方法的参数是您定义偏移量和长度的地方。
此处是分块下载大文件的代码更改(适用于 Azure SDK v12)。
您所要做的就是通过传递起点和长度(或终点)来调用此方法
public Stream DownloadRange(Stream outputStream, Guid containerName, Guid blobName, long offset, long length)
{
var blockBlobClient = new BlockBlobClient(
_configurationKeys.StorageConnectionString
,containerName.ToString(),
,blobName.ToString());
var httpRange = new Azure.HttpRange(offset, length);
var output = blockBlobClient.Download(httpRange);
output.Value.Content.CopyTo(outputStream);
return outputStream;
}
我的文件很大。由于文件太大,我一直在尝试从 Azure blob 存储下载部分文件。
我一直在使用 class CloudBlockBlob
中的 DownloadRangeToStream
方法,它对我来说非常好用。
现在我们计划使用 Azure.Storage.Blobs.Specialized.BlockBlobClient
上传,BlockBlobClient
class 中没有类似的方法下载范围或 blob 块中的文件(不是整个文件,而是一个它的块)
我想知道是否有任何其他方法可以更优化地做同样的事情。!!
检查 class BlockBlobClient. To perform a partial update of the content of a block blob, use the StageBlock(String, Stream, Byte[], BlobRequestConditions, IProgress, CancellationToken) and CommitBlockList(IEnumerable, BlobHttpHeaders, IDictionary<String,String>, BlobRequestConditions, Nullable, CancellationToken) 操作的详细信息。
希望对您有所帮助。
您要使用的方法是 Download(HttpRange, BlobRequestConditions, Boolean, CancellationToken)
which is in BlobBaseClient
class(BlockBlobClient 派生自此 class)。
HttpRange
此方法的参数是您定义偏移量和长度的地方。
此处是分块下载大文件的代码更改(适用于 Azure SDK v12)。 您所要做的就是通过传递起点和长度(或终点)来调用此方法
public Stream DownloadRange(Stream outputStream, Guid containerName, Guid blobName, long offset, long length)
{
var blockBlobClient = new BlockBlobClient(
_configurationKeys.StorageConnectionString
,containerName.ToString(),
,blobName.ToString());
var httpRange = new Azure.HttpRange(offset, length);
var output = blockBlobClient.Download(httpRange);
output.Value.Content.CopyTo(outputStream);
return outputStream;
}