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

喜你入骨 提交于 2019-12-13 05:18:21

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/6884073/azure-cloudblob-setmetadata-fails-with-the-metadata-specified-is-invalid-it-ha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!