简体   繁体   English

有没有办法在 Azure.Storage.Blobs 中获取 blob 的 ContentType?

[英]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.

相关问题 如何使用 C# 中的 Azure.Storage.Blobs 以 ByteArray 格式从 Azure 存储 blob 中获取文件 - How to get file from Azure storage blob in a ByteArray format using Azure.Storage.Blobs in C# 使用 Azure.Storage.Blobs 枚举大型 Azure BLOB 容器 - Enumerating large Azure BLOB containers using Azure.Storage.Blobs 如何使用新的 Azure.Storage.Blobs 命名空间仅获取 blob 中的文件夹名称 - How to get only folder name in blob using new Azure.Storage.Blobs namespace 用于 Azure Blob 管理的 Azure.Storage.Blobs 与 Microsoft.WindowsAzure.Storage.Blob dll - Azure.Storage.Blobs vs Microsoft.WindowsAzure.Storage.Blob dll for Azure Blob management 如何使用 Azure.Storage.Blobs BlobClient 检索 blob 目录路径中的 blob? - How to retrieve blobs within a blob directory path using the Azure.Storage.Blobs BlobClient? 使用新的 Azure.Storage.Blobs 时如何计算存储帐户中 Blob 存储容器的总大小 - How to calculate the total size of Blob storage containers in an storage account when using the new Azure.Storage.Blobs 如何使用 Azure.Storage.Blobs 程序集对 Azure blob 存储操作设置重试策略? - How do I set a retry policy on an Azure blob storage operation using the Azure.Storage.Blobs assembly? 无法使用 Azure.Storage.Blobs NuGet 包将文件上传到 Azure Blob 存储 - Unable to upload a file to Azure Blob Storage using Azure.Storage.Blobs NuGet package Azure.Storage.Blobs 文件夹结构 - Azure.Storage.Blobs Folder Structure 如何模拟 Azure.Storage.Blobs 的 BlobContainerClient()? - How to Mock BlobContainerClient() of Azure.Storage.Blobs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM