您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

命名和引用容器、Blob 和元数据Naming and Referencing Containers, Blobs, and Metadata

本主题介绍了如何命名和引用容器、Blob、元数据和快照。This topic describes naming and referring to containers, blobs, metadata, and snapshots. 存储帐户可包含零个或多个容器。A storage account can contain zero or more containers. 容器包含属性、元数据以及零个或多个 Blob。A container contains properties, metadata, and zero or more blobs. Blob 是由二进制数据、属性和元数据组成的任一实体。A blob is any single entity comprised of binary data, properties, and metadata.

资源名称Resource Names

引用容器或 Blob 的 URI 必须是唯一的。The URI to reference a container or a blob must be unique. 由于每个帐户名称都是唯一的,因此两个帐户可具有同名容器。Because every account name is unique, two accounts can have containers with the same name. 但是,在给定的存储帐户中,每个容器均必须具有一个唯一名称。However, within a given storage account, every container must have a unique name. 此外,给定容器中的每个 Blob 必须在该容器中拥有一个唯一名称。Every blob within a given container must also have a unique name within that container.

如果您尝试使用违反命名规则的名称创建容器或 Blob,则请求将失败,状态代码为 400(错误的请求)。If you attempt to create a container or blob with a name that violates naming rules, the request will fail with status code 400 (Bad Request).

重要

Blob 和容器名称将传递给 URL 中的 BLOB 服务。Blob and container names are passed to the Blob service within a URL. 某些字符必须使用 UTF-8(首选)或 MBCS 以百分比编码形式出现在 URL 中。Certain characters must be percent-encoded to appear in a URL, using UTF-8 (preferred) or MBCS. 当你使用 Azure 存储客户端库时,将自动进行此编码。This encoding occurs automatically when you use the Azure Storage client libraries. 但是,即使经过编码,还是有一些字符在 URL 路径中无效。However, there are certain characters that are not valid in URL paths even when encoded. 这些字符不能出现在 Blob 或容器名称中。These characters cannot appear in blob or container names. 像 \uE000 这样的码位虽然在 NTFS 文件名中有效,但不是有效的 Unicode 字符,因此无法使用。Code points like \uE000, while valid in NTFS filenames, are not valid Unicode characters, so they cannot be used. 此外,也不允许使用某些 ASCII 或 Unicode 字符,如控制字符(0x00 到 0x1F、\u0081 等)。In addition, some ASCII or Unicode characters, like control characters (0x00 to 0x1F, \u0081, etc.), are also not allowed. 有关在 HTTP/1.1 中控制 Unicode 字符串的规则,请参阅RFC 2616,第2.2 节:基本规则RFC 3987For rules governing Unicode strings in HTTP/1.1, see RFC 2616, Section 2.2: Basic Rules and RFC 3987.

容器名称Container Names

容器名称必须是有效的 DNS 名称,并符合以下命名规则:A container name must be a valid DNS name, conforming to the following naming rules:

  • 容器名称必须以字母或数字开头或结尾,并且只能包含字母、数字和短划线(-)字符。Container names must start or end with a letter or number, and can contain only letters, numbers, and the dash (-) character.

  • 每个短划线 (-) 字符的前面和后面都必须是一个字母或数字;在容器名称中不允许连续的短划线 (-)。Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.

  • 容器名称中的所有字母都必须为小写。All letters in a container name must be lowercase.

  • 容器名称必须介于 3 到 63 个字符。Container names must be from 3 through 63 characters long.

Blob 名称Blob Names

Blob 名称必须符合以下命名规则:A blob name must conforming to the following naming rules:

  • Blob 名称可以包含任何字符组合。A blob name can contain any combination of characters.

  • Blob 名称的长度必须至少为1个字符,且对于 Azure 存储中的 blob,长度不能超过1024个字符。A blob name must be at least one character long and cannot be more than 1,024 characters long, for blobs in Azure Storage.

    Azure 存储模拟器支持长度最大为256个字符的 blob 名称。The Azure Storage emulator supports blob names up to 256 characters long. 有关详细信息,请参阅使用 Azure 存储模拟器进行开发和测试For more information, see Use the Azure storage emulator for development and testing.

  • Blob 名称区分大小写。Blob names are case-sensitive.

  • 必须正确地对保留的 URL 字符进行转义。Reserved URL characters must be properly escaped.

  • 构成 Blob 名称的路径段数目不能超过 254 个。The number of path segments comprising the blob name cannot exceed 254. 路径段是连续分隔符(例如,正斜杠 "/")与虚拟目录名称对应的字符串。A path segment is the string between consecutive delimiter characters (e.g., the forward slash '/') that corresponds to the name of a virtual directory.

备注

避免以点 (.)、正斜杠 (/) 或二者的序列或组合结尾的 Blob 名称。Avoid blob names that end with a dot (.), a forward slash (/), or a sequence or combination of the two.

BLOB 服务基于平面存储方案而不是分层方案。The Blob service is based on a flat storage scheme, not a hierarchical scheme. 但是,可以在 Blob 名称中指定字符或字符串分隔符来创建虚拟层次结构。However, you may specify a character or string delimiter within a blob name to create a virtual hierarchy. 例如,以下列表显示了有效的唯一 Blob 名称。For example, the following list shows valid and unique blob names. 请注意,在同一容器中,作为 Blob 名称和虚拟目录名称的字符串是有效的:Notice that a string can be valid as both a blob name and as a virtual directory name in the same container:

  • /a/a

  • /a.txt/a.txt

  • /a/b/a/b

  • /a/b.txt/a/b.txt

枚举 Blob 时可使用分隔符。You can take advantage of the delimiter character when enumerating blobs.

元数据名称Metadata Names

容器或 Blob 资源的元数据将存储为与该资源关联的名称值对。Metadata for a container or blob resource is stored as name-value pairs associated with the resource. 元数据名称必须遵循c # 标识符的命名规则。Metadata names must adhere to the naming rules for C# identifiers.

请注意,元数据名称保留在创建时具有的大小写形式,但在设置或读取时不区分大小写。Note that metadata names preserve the case with which they were created, but are case-insensitive when set or read. 如果为资源提交两个或多个具有相同名称的元数据标头,Blob 服务将返回状态代码 400(错误的请求)。If two or more metadata headers with the same name are submitted for a resource, the Blob service returns status code 400 (Bad Request).

资源 URI 语法Resource URI Syntax

每个资源均具有一个对应的基本 URI,它指的是资源本身。Each resource has a corresponding base URI, which refers to the resource itself.

对于存储帐户,基本 URI 仅包含帐户的名称:For the storage account, the base URI includes the name of the account only:

https://myaccount.blob.core.windows.net

对于容器,基本 URI 包含帐户名称和容器名称:For a container, the base URI includes the name of the account and the name of the container:

https://myaccount.blob.core.windows.net/mycontainer

对于 Blob,基本 URI 包含帐户名称、容器名称和 Blob 名称:For a blob, the base URI includes the name of the account, the name of the container, and the name of the blob:

https://myaccount.blob.core.windows.net/mycontainer/myblob

存储帐户可具有根容器(它是可从 URI 中忽略的默认容器)。A storage account may have a root container, a default container that can be omitted from the URI. 可以在不命名容器的情况下引用根容器中的 Blob,也可以按根容器的名称 ($root) 显式引用它。A blob in the root container can be referenced without naming the container, or the root container can be explicitly referenced by its name ($root). 有关详细信息,请参阅使用根容器See Working with the Root Container for more information. 以下 URI 指根容器中的 Blob:The following URIs both refer to a blob in the root container:

https://myaccount.blob.core.windows.net/myblob  
https://myaccount.blob.core.windows.net/$root/myblob  

Blob 快照Blob Snapshots

快照是指 Blob 在创建快照时所存储的状态的只读版本。A snapshot is a read-only version of a blob stored as it was at the time the snapshot was created. 可以使用快照创建 Blob 的备份或检查点。You can use snapshots to create a backup or checkpoint of a blob. 快照 Blob 名称包含基本 Blob URI 和日期时间值,该值指示快照的创建时间。A snapshot blob name includes the base blob URI plus a date-time value that indicates when the snapshot was created.

例如,假设 Blob 具有以下 URI:For example, assume that a blob has the following URI:

https://myaccount.blob.core.windows.net/mycontainer/myblob

该 Blob 的快照 URI 的格式如下所示:The URI for a snapshot of that blob is formed as follows:

https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=<DateTime>

另请参阅See also