SDK在具有指定ContentType的Azure

SDK在具有指定ContentType的Azure

本文介绍了如何使用.NET v12 SDK在具有指定ContentType的Azure Blob存储中上载blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从.NET v12 SDK开始快速入门 https://docs.microsoft.com/da-dk/azure/storage/blobs/storage-quickstart-blobs-dotnet

I just started the Quickstart with .NET v12 SDK https://docs.microsoft.com/da-dk/azure/storage/blobs/storage-quickstart-blobs-dotnet

但是我似乎无法找出上传blob时如何指定ContentType.

But i cant seem to find out how to specify a ContentType when uploading a blob.

有人知道吗?

谢谢.

推荐答案

您可以将其设置如下,

 await blobClient.UploadAsync(stream, true, default);
 await blobClient.SetHttpHeadersAsync(new BlobHttpHeaders
 {
    ContentType = contentType
 });

编辑:如评论中所述,一种有效的方法可通过以下一种方法完成操作,

As mentioned in the comment, the efficient way to do the same with a single method as follows,

await blobClient.UploadAsync(ms, new BlobHttpHeaders{ ContentType = "text/plain"});

这篇关于如何使用.NET v12 SDK在具有指定ContentType的Azure Blob存储中上载blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:41