I noticed in the debug trace my current approach is triggering a HEAD on the blob - presumably to check if it already exists. I know it never will, and if it did exist I want to overwrite. I just want a straight PUT to shave a few milliseconds and importantly reduce noise in Application Insights Application map where HTTP 404 errors show up as failures on Azure Blob dependency.
There is no option within BlobHttpHeaders, neither can I find any such overwrite option in BlobUploadOptions. What am I missing ?
I want to do all the work of setting Content-Type and Tags in a single call. I am aware of the below override, but that would entail subsequent requests to set Content-Type and Tags which I want to avoid.
UploadAsync(Stream content, bool overwrite = false, CancellationToken cancellationToken = default)
SDK Assembly Azure.Storage.Blobs, Version=12.10.0.0
My current code:
// blob settings
var options = new BlobUploadOptions()
{
// set content type
HttpHeaders = new BlobHttpHeaders()
{
ContentType = contentType,
ContentEncoding = "UTF-8"
},
// Set blob index tags
Tags = new Dictionary<string, string>
{
{ "quoteid", "123" },
{ "responseId","456" }
}
};
// upload blob
var content = Encoding.UTF8.GetBytes(data);
using var ms = new MemoryStream(content);
await blobClient.UploadAsync(
ms,
options
);
Update:
- The HEAD is being triggered by BlobBaseClient.Exists
- Also asked on GitHub by someone else
There is no option within BlobHttpHeaders, neither can I find any such overwrite option in BlobUploadOptions.
- That's not true. Have you looked at HttpHeaders property here - learn.microsoft.com/en-us/dotnet/api/…?UploadAsync(Stream, BlobUploadOptions, CancellationToken)