gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:24:26 25 4
gpt4 key购买 nike

我正在切换到较新的 Azure.Storage.Blobs,并希望通过 API 将 Blob 作为文件提供给客户端。

在现已弃用的 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;

现在我在 Azure.Storage.Blobs 中,设置看起来相同,但我缺少要点:

using Azure.Storage.Blobs;
BlobContainerClient containerClient = new BlobContainerClient(storageConnectionString, containerName);
BlobClient blobClient = containerClient.GetBlobClient("foo");

较新的库中没有类似的 blockblob,我可以将 blobClient 读入流中,但是在不求助于旧库的情况下如何获取其内容类型?

我希望能够命中 FileResult,返回与此签名匹配的内容:

File(Stream fileStream, string contentType, string fileName);

最佳答案

您可以使用 GetBlobProperties 获取 blob 的属性这将为您提供 blob 的内容类型。像(未经测试的代码):

var getBlobPropertiesResult = blobClient.GetProperties();
var contentType = getBlobPropertiesResult.Value.ContentType;

关于c# - 有没有办法在 Azure.Storage.Blobs 中获取 blob 的 ContentType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66569363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com