使用Azure Blob存储客户端库v12 for .NET下载blob

问题描述 投票:0回答:1

我正在使用Azure.Storage.Blobs版本12.4.1.1。我有一个REST端点,我想用来从存储帐户下载blob。

我需要将结果流式传输到HttpResponseMessage,并且我不想使用MemoryStream。我想将结果直接流式传输到调用客户端。有没有办法实现这一目标。如何在HttpResponseMessage内容中获取下载的Blob?我不想使用MemoryStream,因为会有很多下载请求。

BlobClient类具有方法DownloadToAsync,但它需要Stream作为参数。

        var result = new HttpResponseMessage(HttpStatusCode.OK);

        var blobClient = container.GetBlobClient(blobPath);
        if (await blobClient.ExistsAsync())
        {
            var blobProperties = await blobClient.GetPropertiesAsync();

            var fileFromStorage = new BlobResponse()
            {                    
                ContentType = blobProperties.Value.ContentType,
                ContentMd5 = blobProperties.Value.ContentHash.ToString(),
                Status = Status.Ok,
                StatusText = "File retrieved from blob"
            };

            await blobClient.DownloadToAsync(/*what to put here*/);
            return fileFromStorage;
        }
.net azure azure-storage azure-storage-blobs azure-sdk
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.