无效字符异常时,添加元数据到CloudBlob [英] Invalid character exception when adding Metadata to a CloudBlob
问题描述
上传文件的Azure Blob存储
与原来的文件名,并指定文件名作为的元数据
来在 CloudBlob
Upload a file to Azure Blob Storage
with the original filename and also assign the filename as meta-data
to the CloudBlob
这些字符不是在的元数据允许
,但作为一滴
名接受:
These characters are not permitted in the meta-data
but are acceptable as the blob
name:
š Š ñ Ñ ç Ç ÿ Ÿ ž Ž Ð œ Œ « » éèëêð ÉÈËÊ àâä ÀÁÂÃÄÅ àáâãäå ÙÚÛÜ ùúûüµ òóôõöø ÒÓÔÕÖØ ìíîï ÌÍÎÏ
问题
- 有没有这些字符存储在
的元数据的方式
?我们是否缺少某些设置,导致此异常? - 大多数这些字符是在某些语言标准字形,所以如何处理这个问题?
- 是否有任何文件可用的建议对这个问题?我发现
一滴
和的元数据
命名约定,但没有对数据本身! - Is there a way to store these characters in the
meta-data
? Are we missing some setting that causes this exception? - Most of these characters are standard glyphs in some languages, so how to handle that?
- Is there any documentation available that advises about this issue? I found
blob
andmeta-data
naming conventions, but none about the data itself!
Question
var dirtyFileName = file.FileName;
var normalizedFileName = file.FileName.CleanOffDiacriticAndNonASCII();
// Blob name accepts almost characters that are acceptable as filenames in Windows
var blob = container.GetBlobReference(dirtyFileName);
//Upload content to the blob, which will create the blob if it does not already exist.
blob.Metadata["FileName"] = normalizedFileName;
blob.Attributes.Properties.ContentType = file.ContentType;
// ERROR: Occurs here!
blob.UploadFromStream(file.InputStream);
blob.SetMetadata();
blob.SetProperties();
错误
- 命名和引用容器,斑点,和元数据
- How支持的Azure Blob存储其他的语言吗?
- How我在.NET中的字符串中删除变音符号(重音)?
- Azure CloudBlob SetMetadata失败,指定的元数据是无效的。它有不允许的字符。
- Replacing在C#(ASCII) 字符
- Naming and Referencing Containers, Blobs, and Metadata
- How to support other languages in Azure blob storage?
- How do I remove diacritics (accents) from a string in .NET?
- Azure CloudBlob SetMetadata fails with "The metadata specified is invalid. It has characters that are not permitted."
- Replacing characters in C# (ascii)
在文件名非法字符只有冰冰山一角,只为这一问题的目的,放大了!更大的画面是,我们的索引使用这些文件 Lucene.net
,因此需要大量的的元数据
的要存储在一滴
。 请不要建议在数据库分开存储这一切,只是不!的到现在为止,我们一直很幸运,只有所遇到的一个文件具有变音符的字符!
Illegal characters in filename is only the tip of the ice-berg, magnified only for the purpose of this question! The bigger picture is that we index these files using Lucene.net
and as such need a lot of meta-data
to be stored on the blob
. Please don't suggest storing it all separately in a database, just don't! Up until now we have been lucky to only have come across one file with diacritic characters!
所以,目前我们正在努力,以避免保存在文件名的元数据
作为一种解决方法!
So, at the moment we are making the effort to avoid saving the filename in the meta-data
as a workaround!
推荐答案
从 Azure的SDK换网
团队在GitHub上的,只有 ASCII
字符为 BLOB的元数据
。
Just have had confirmation from the azure-sdk-for-net
team on GitHub that only ASCII
characters are valid as data within blob meta-data
.
joeg评论说:结果
在BLOB元数据支持的字符必须是ASCII字符。要解决
这个您可以逃脱字符串(百分号EN code),恩的base64 code等。
joeg commented:
The supported characters in the blob metadata must be ASCII characters. To work around this you can either escape the string ( percent encode), base64 encode etc.
因此,作为一个变通,无论是:
So as a work-around, either:
- escape the string (percent encode), base64 encode, etc, as suggested by joeg
- use the techniques that I have mentioned in my other answer.
这篇关于无效字符异常时,添加元数据到CloudBlob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!