Megrez7
Megrez7

Reputation: 1457

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?

Upvotes: 3

Views: 760

Answers (1)

Harshitha Veeramalla
Harshitha Veeramalla

Reputation: 1743

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

Upvotes: 4

Related Questions