简体   繁体   中英

Upload blob into Azure Blob Storage with specified ContentType and overwrite same time (.NET v12 SDK)?

I am trying to upload Blob from Stream with.Net 12 SDK, setting ContentType and overwrite property to true same time.

There are few overloads of BlobClient.Upload method. But none of them accepts both parameters.

As an alternative I can set ContentType in the second step, but would prefer to do in one.

BlobHttpHeaders blobHttpHeaders = new BlobHttpHeaders();
blobHttpHeaders.ContentType = "text/xml";
blobClient.SetHttpHeaders(blobHttpHeaders);

Is that possible in one run?

The efficient way to do the same with a single method is as follows,

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

OR

 using Stream stream = file.ToStream();
 var result = await blobClient.UploadAsync(stream, new BlobHttpHeaders { ContentType = "text/xml" });   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM