Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I just started the Quickstart with .NET v12 SDK https://learn.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.

like image 808
Danny Chu Avatar asked Dec 11 '22 01:12

Danny Chu


1 Answers

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"});
like image 97
Sajeetharan Avatar answered Dec 12 '22 21:12

Sajeetharan