Azure CloudBlob SetMetadata 失败,并显示“指定的元数据无效。它包含不允许的字符。”
我很确定这是 Windows Azure SDK 的限制(使用最新的 1.4),但是必须有一种方法可以解决这个问题,而无需使用手动 REST...
代码:
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
从我的测试中可以清楚地看出由于这些破折号“-”,客户端正在爆炸,但我想不出任何解决办法。设置缓存控制非常重要,也是常见的操作,这让我很困惑为什么我找不到其他人报告这个问题。
我还尝试过对数据进行编码,这在技术上是不必要的,但出于绝望,我还是这么做了。有想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
毕竟,它最终成为一个愚蠢的 SDK 限制,有一个特定的属性反过来为您设置特定的元数据...我不介意将此属性作为帮助器,但我认为没有理由设置元数据直接不应该工作。
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.
今天您仍然会收到此消息,但替换了 nuget 包 Azure.Storage.Blobs 版本 12.14.1 中的“BlobContainerClient”。以下是既适用于 Azurite 又部署在 Azure 中的使用版本:
允许的特殊字符:
https://learn.microsoft.com/en-us/rest/api/storageservices/set-blob-tags?source=recommendations&tabs=azure-ad
You get this message still today but with the replacing 'BlobContainerClient' in nuget package Azure.Storage.Blobs, version 12.14.1. Below is a version of usage that works both with Azurite and deployed in Azure:
Allowed special characters:
https://learn.microsoft.com/en-us/rest/api/storageservices/set-blob-tags?source=recommendations&tabs=azure-ad