Search code examples
azureazure-storage

Azure CloudBlob SetMetadata fails with "The metadata specified is invalid. It has characters that are not permitted."


I'm pretty sure this is a limitation of the Windows Azure SDK (Using the latest, 1.4), but there has got to be a way around this without using manual REST...

The code:

CloudBlob blob = container.GetBlobReference(url); // works
blob.UploadByteArray(bytes); // works
blob.Metadata["test"] = "public, max-age=259200"; // works
// FAILS with "The metadata specified is invalid. It has characters that are not permitted."
blob.Metadata["x-ms-blob-cache-control"] = "public, max-age=259200";
blob.SetMetadata(); // FAILS due to the 2nd meta data

It's pretty clear from my tests that the client is blowing up due to these dashes '-', but I cannot think of any way around this. Setting cache control is very important, and common operation, which baffles me as to why I cannot find anyone else reporting on this problem.

I've also tried encoding the data, which technically shouldn't be necessary, but out of desperation I did it anyway. Ideas?


Solution

  • It ended up being a silly SDK limitation after all, there is a specific property which in turns sets that specific meta data for you... I don't mind having this property as a helper, but I see no reason why setting the meta directly shouldn't work.

    blob.Properties.CacheControl = "public, max-age=259200";
    blob.UploadByteArray(bytes);