How upload blob in Azure Blob Storage with specified ContentType with .NET v12 SDK?

﹥>﹥吖頭↗ 提交于 2020-03-15 05:50:08

问题


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

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

Does anyone know that?

Thanks in advance.


回答1:


You can set it as follows,

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

EDIT: 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"});



回答2:


Please try this override of UploadAsync method. This method will upload and set the content type in a single network call.

Here would be your code:

var httpHeaders = new BlobHttpHeaders
 {
    ContentType = contentType
 });
await blobClient.UploadAsync(stream, httpHeaders);


来源:https://stackoverflow.com/questions/59945376/how-upload-blob-in-azure-blob-storage-with-specified-contenttype-with-net-v12-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!