3

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?

Aaron
  • 475
  • 3
  • 14

1 Answers1

4

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);
Aaron
  • 475
  • 3
  • 14
  • 2
    Metadata is different from headers... if allowed, blob.Metadata["x-ms-blob-cache-control"] would send a header of "x-ms-meta-x-ms-blob-cache-control". (The "x-ms-meta" is there specifically to distinguish metadata from other kinds of headers.) – user94559 Jul 30 '11 at 17:31
  • 3
    In general, note that the rule concerning metadata is that the key has to follow C# identifier naming rules: http://msdn.microsoft.com/en-us/library/dd179414.aspx. (That's why you got an error.) – user94559 Jul 30 '11 at 17:34
  • I'm facing a similar issue when setting "filename" metadata. Do you know a workaround for that? – gayashanbc Aug 03 '21 at 14:38