DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Ricardo Costa
Ricardo Costa

Posted on • Originally published at blogit.create.pt on

Azure Blob Storage Metadata 400 Bad Request

I was getting a 400 Bad Request when inserting blobs in Azure Blob Storage because I was setting metadata with non-ASCII characters.

// Retrieve storage account from connection string. 
CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); 

// Create the blob client. 
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); 

// Retrieve a reference to a container. 
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); 

// Create the container if it doesn't already exist.
container.CreateIfNotExists(); 

// Add some metadata to the container. 
container.Metadata.Add("docType", "textDocuments");

According to Microsfot documentation:

β€œYou will receive a 400 Bad Request if any name/value pairs contain non-ASCII characters. Metadata name/value pairs are valid HTTP headers, and so must adhere to all restrictions governing HTTP headers. It is therefore recommended that you use URL encoding or Base64 encoding for names and values containing non-ASCII characters.”

https://docs.microsoft.com/en-us/azure/storage/blobs/storage-properties-metadata

The post Azure Blob Storage Metadata 400 Bad Request appeared first on Blog IT.

Top comments (0)

πŸ‘‹ Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: