无效字符异常时,添加元数据到CloudBlob [英] Invalid character exception when adding Metadata to a CloudBlob

查看:413
本文介绍了无效字符异常时,添加元数据到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:

š Š ñ Ñ ç Ç ÿ Ÿ ž Ž Ð œ Œ « » éèëêð ÉÈËÊ àâä ÀÁÂÃÄÅ àáâãäå ÙÚÛÜ ùúûüµ òóôõöø ÒÓÔÕÖØ ìíîï ÌÍÎÏ

问题


  • 有没有这些字符存储在的元数据的方式?我们是否缺少某些设置,导致此异常?

  • 大多数这些字符是在某些语言标准字形,所以如何处理这个问题?

  • 是否有任何文件可用的建议对这个问题?我发现一滴的元数据命名约定,但没有对数据本身!

  • Question

    • 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 and meta-data naming conventions, but none about the data itself!
    • 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();
      

      错误

      异常

      • 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.

      源GitHub上

      因此​​,作为一个变通,无论是:

      So as a work-around, either:


      • 转义字符串(百分号EN code),恩的base64 code等,由 joeg
      • 使用,我在我的对方的回答。

      • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆