[英]Is there a way to get a blob's ContentType in Azure.Storage.Blobs?
I'm switching to the newer Azure.Storage.Blobs and want to serve up a blob as a file via API to a client.我正在切换到较新的 Azure.Storage.Blobs 并希望通过 API 将 blob 作为文件提供给客户端。
In the now-deprecated Microsoft.Azure.Storage and Microsoft.Azure.Storage.Blob, I was able to do it like this:在现已弃用的 Microsoft.Azure.Storage 和 Microsoft.Azure.Storage.Blob 中,我可以这样做:
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Blob;
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.GetContainerReference("foo");
CloudBlockBlob blob = container.GetBlockBlobReference(blobId);
var bar = blob.Properties.ContentType;
Now that I'm in Azure.Storage.Blobs, the setup looks the same, but I'm missing the punchline:现在我在 Azure.Storage.Blobs 中,设置看起来一样,但我错过了重点:
using Azure.Storage.Blobs;
BlobContainerClient containerClient = new BlobContainerClient(storageConnectionString, containerName);
BlobClient blobClient = containerClient.GetBlobClient("foo");
There's no analogous blockblob in the newer library, I can read the blobClient into a stream, but where do I get its content type without resorting to older libraries?较新的库中没有类似的块blob,我可以将 blobClient 读入 stream,但是在不求助于旧库的情况下,我从哪里获得它的内容类型?
I'm hoping to be able to hit a FileResult, returning something that matches this signature:我希望能够点击 FileResult,返回与此签名匹配的内容:
File(Stream fileStream, string contentType, string fileName);
You can fetch blob's properties using GetBlobProperties and that will give you the content type of the blob.您可以使用GetBlobProperties获取 blob 的属性,这将为您提供 blob 的内容类型。 Something like (untested code):
类似(未经测试的代码):
var getBlobPropertiesResult = blobClient.GetProperties();
var contentType = getBlobPropertiesResult.Value.ContentType;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.