我正在使用Azure.Storage.Blobs版本12.4.1。我有一个REST端点,想要使用它从存储帐户下载blob。
我需要将结果流式传输到HttpResponseMessage中,并且不想使用MemoryStream。我想直接将结果流式传输到调用客户端。有没有方法可以实现这一点?如何在HttpResponseMessage内容中获取下载的blob?由于会有大量的下载请求,我不想使用MemoryStream。
BlobClient类有一个DownloadToAsync方法,但它需要一个Stream作为参数。
我需要将结果流式传输到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;
}
CreateCloudBlobClient
这样的方法,这是针对Legacy Azure SDK for .NET的。如果有人使用最新的Azure SDK for .NET和较新版本的Azure.Storage.Blobs v12,则我将提供更更新的解决方案。 - kimbaudi