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

放置 BlobPut Blob

Put Blob操作创建新的块、页面或追加 blob,或更新现有块 blob 的内容。The Put Blob operation creates a new block, page, or append blob, or updates the content of an existing block blob.

更新现有块 Blob 会覆盖该 Blob 的所有现有元数据。Updating an existing block blob overwrites any existing metadata on the blob. Put Blob不支持部分更新;现有 blob 的内容会被新 blob 的内容覆盖。Partial updates are not supported with Put Blob; the content of the existing blob is overwritten with the content of the new blob. 若要对块 blob 的内容执行部分更新,请使用Put 块列表操作。To perform a partial update of the content of a block blob, use the Put Block List operation.

请注意,只能在版本2015-02-21 和更高版本中创建追加 blob。Note that you can create an append blob only in version 2015-02-21 and later.

若要 Put Blob 创建页 blob 或追加 blob,则调用将仅初始化 blob。A call to a Put Blob to create a page blob or an append blob only initializes the blob. 若要向页 blob 添加内容,请调用Put 页操作。To add content to a page blob, call the Put Page operation. 若要将内容添加到追加 blob,请调用追加阻止操作。To add content to an append blob, call the Append Block operation.

请求Request

可以按如下方式构建Put Blob请求。The Put Blob request may be constructed as follows. 建议使用 HTTPS。HTTPS is recommended. 我的帐户替换为你的存储帐户的名称:Replace myaccount with the name of your storage account:

PUT 方法请求 URIPUT Method Request URI HTTP 版本HTTP Version
https://myaccount.blob.core.windows.net/mycontainer/myblob HTTP/1.1HTTP/1.1

模拟的存储服务 URIEmulated storage service URI

在针对模拟的存储服务发出请求时,请将模拟器主机名和 BLOB 服务端口指定为 127.0.0.1:10000,后跟模拟的存储帐户名称:When making a request against the emulated storage service, specify the emulator hostname and Blob service port as 127.0.0.1:10000, followed by the emulated storage account name:

PUT 方法请求 URIPUT Method Request URI HTTP 版本HTTP Version
http://127.0.0.1:10000/devstoreaccount1/mycontainer/myblob HTTP/1.1HTTP/1.1

请注意,存储模拟器仅支持最大为 2 GiB 的 blob 大小。Note that the storage emulator only supports blob sizes up to 2 GiB.

有关详细信息,请参阅使用 Azure 存储模拟器进行开发和测试For more information, see Using the Azure Storage Emulator for Development and Testing.

URI 参数URI Parameters

可以在请求 URI 上指定以下附加参数。The following additional parameters may be specified on the request URI.

参数Parameter 说明Description
timeout 可选。Optional. 必须向The

超时参数以秒表示。timeout parameter is expressed in seconds. 有关详细信息,请参阅为Blob 服务操作设置超时For more information, see Setting Timeouts for Blob Service Operations.

请求标头(所有 Blob 类型)Request Headers (All Blob Types)

下表描述了所有 blob 类型的必需和可选的请求标头。The following table describes required and optional request headers for all blob types.

请求标头Request header 说明Description
Authorization 必需。Required. 指定授权方案、帐户名和签名。Specifies the authorization scheme, account name, and signature. 有关详细信息,请参阅授权 Azure 存储的请求For more information, see Authorize requests to Azure Storage.
Datex-ms-dateDate or x-ms-date 必需。Required. 指定请求的协调世界时 (UTC)。Specifies the Coordinated Universal Time (UTC) for the request. 有关详细信息,请参阅授权 Azure 存储的请求For more information, see Authorize requests to Azure Storage.
x-ms-version 所有授权的请求都需要此权限。Required for all authorized requests. 指定用于此请求的操作的版本。Specifies the version of the operation to use for this request. 有关详细信息,请参阅Azure 存储服务的版本控制For more information, see Versioning for the Azure Storage Services.
Content-Length 必需。Required. 请求的长度。The length of the request.

对于页 blob 或追加 blob,此标头的值必须设置为零,因为Put blob仅用于初始化 blob。For a page blob or an append blob, the value of this header must be set to zero, as Put Blob is used only to initialize the blob. 若要将内容写入现有页 blob,请调用Put 页To write content to an existing page blob, call Put Page. 若要将内容写入追加 blob,请调用Append 块To write content to an append blob, call Append Block.
Content-Type 可选。Optional. Blob 的 MIME 内容类型。The MIME content type of the blob. 默认类型为 application/octet-streamThe default type is application/octet-stream.
Content-Encoding 可选。Optional. 指定对 Blob 应用了哪种内容编码。Specifies which content encodings have been applied to the blob. 当对 blob 资源执行Get Blob操作时,此值将返回到客户端。This value is returned to the client when the Get Blob operation is performed on the blob resource. 返回时客户端可以使用此值解码 Blob 内容。The client can use this value when returned to decode the blob content.
Content-Language 可选。Optional. 指定此资源使用的自然语言。Specifies the natural languages used by this resource.
Content-MD5 可选。Optional. Blob 内容的 MD5 哈希值。An MD5 hash of the blob content. 此哈希值用于验证传输期间 Blob 的完整性。This hash is used to verify the integrity of the blob during transport. 指定此标头时,存储服务会对已到达的哈希值与所发送的哈希值进行比较。When this header is specified, the storage service checks the hash that has arrived with the one that was sent. 如果这两个哈希值不匹配,操作会失败,并显示错误代码 400(错误请求)。If the two hashes do not match, the operation will fail with error code 400 (Bad Request).

在版本 2012-02-12 和更新版本中省略此值时,BLOB 服务会生成一个 MD5 哈希值。When omitted in version 2012-02-12 and later, the Blob service generates an MD5 hash.

获取 blob获取 Blob 属性列表 blob的结果包含 MD5 哈希。Results from Get Blob, Get Blob Properties, and List Blobs include the MD5 hash.
x-ms-content-crc64 可选。Optional. Blob 内容的 CRC64 哈希。A CRC64 hash of the blob content. 此哈希值用于验证传输期间 Blob 的完整性。This hash is used to verify the integrity of the blob during transport. 指定此标头时,存储服务会对已到达的哈希值与所发送的哈希值进行比较。When this header is specified, the storage service checks the hash that has arrived with the one that was sent. 如果这两个哈希值不匹配,操作会失败,并显示错误代码 400(错误请求)。If the two hashes do not match, the operation will fail with error code 400 (Bad Request). 此标头在02-02-2019 版或更高版本中受支持。This header is supported in versions 02-02-2019 or later.

如果同时存在内容 MD5 和 crc64 标头,则请求将失败,并出现400(错误请求)。If both Content-MD5 and x-ms-content-crc64 headers are present, the request will fail with a 400 (Bad Request).
Cache-Control 可选。Optional. BLOB 服务存储此值,但并不使用或修改它。The Blob service stores this value but does not use or modify it.
x-ms-blob-content-type 可选。Optional. 设置 Blob 的内容类型。Set the blob’s content type.
x-ms-blob-content-encoding 可选。Optional. 设置 Blob 的内容编码。Set the blob’s content encoding.
x-ms-blob-content-language 可选。Optional. 设置 Blob 的内容语言。Set the blob's content language.
x-ms-blob-content-md5 可选。Optional. 设置 Blob 的 MD5 哈希值。Set the blob’s MD5 hash.
x-ms-blob-cache-control 可选。Optional. 设置 Blob 的缓存控制。Sets the blob's cache control.
x-ms-blob-type: <BlockBlob | PageBlob | AppendBlob> 必需。Required. 指定要创建的 blob 类型:块 blob、页 blob 或追加 blob。Specifies the type of blob to create: block blob, page blob, or append blob. 仅在版本2015-02-21 和更高版本中提供了对创建追加 blob 的支持。Support for creating an append blob is available only in version 2015-02-21 and later.
x-ms-meta-name:value 可选。Optional. 作为元数据、与 Blob 关联的名称-值对。Name-value pairs associated with the blob as metadata.

请注意,从版本2009-09-19 开始,元数据名称必须遵循c # 标识符的命名规则。Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers.
x-ms-encryption-scope 可选。Optional. 指示用于加密请求内容的加密范围。Indicates the encryption scope to use to encrypt the request contents. 此标头在2019-02-02 版或更高版本中受支持。This header is supported in versions 2019-02-02 or later.
x-ms-tags 可选。Optional. 在 blob 上设置给定的查询字符串编码标记。Sets the given query-string encoded tags on the blob. 有关其他信息,请参阅 "备注"。See the Remarks for additional information. 在版本2019-12-12 和更高版本中受支持。Supported in version 2019-12-12 and newer.
x-ms-lease-id:<ID> 如果 Blob 具有活动租约,则是必需的。Required if the blob has an active lease. 要在具有活动租约的 Blob 上执行此操作,请为此标头指定有效的租约 ID。To perform this operation on a blob with an active lease, specify the valid lease ID for this header.
x-ms-blob-content-disposition 可选。Optional. 设置 Blob 的 Content-Disposition 标头。Sets the blob’s Content-Disposition header. 适用于版本 2013-08-15 和更高版本。Available for versions 2013-08-15 and later.

Content-Disposition 响应标头字段传达有关如何处理响应负载的详细信息,也可用于附加更多元数据。The Content-Disposition response header field conveys additional information about how to process the response payload, and also can be used to attach additional metadata. 例如,如果设置为 attachment,它指示用户代理不应显示响应,而是应显示指定了文件名而非 Blob 名称的 “另存为” 对话框。For example, if set to attachment, it indicates that the user-agent should not display the response, but instead show a Save As dialog with a filename other than the blob name specified.

"获取 blob " 和 "获取 blob 属性" 操作的响应包含 content-disposition 标头。The response from the Get Blob and Get Blob Properties operations includes the content-disposition header.
Origin 可选。Optional. 指定从中发出请求的来源。Specifies the origin from which the request is issued. 如果存在此标头,则会在响应中产生跨域资源共享标头。The presence of this header results in cross-origin resource sharing headers on the response. 有关详细信息,请参阅对存储服务的 CORS 支持See CORS Support for the Storage Services for details.
x-ms-client-request-id 可选。Optional. 提供客户端生成的、具有1个 KiB 字符限制的不透明值,当启用存储分析日志记录时,将记录在分析日志中。Provides a client-generated, opaque value with a 1 KiB character limit that is recorded in the analytics logs when storage analytics logging is enabled. 强烈建议使用此标头将客户端活动与服务器接收的请求相关联。Using this header is highly recommended for correlating client-side activities with requests received by the server. 有关详细信息,请参阅关于存储分析日志记录Azure 日志记录:使用日志跟踪存储请求For more information, see About Storage Analytics Logging and Azure Logging: Using Logs to Track Storage Requests.
x-ms-access-tier 可选。Optional. 指示要在 blob 上设置的层。Indicates the tier to be set on blob. 仅适用于高级存储帐户的页 blob 版本2017-04-17 和更高版本。For page blobs on a premium storage account only with version 2017-04-17 and newer. 查看适用于 vm 的高性能高级存储和托管磁盘,以获取支持的页 blob 的完整列表。Check High-performance Premium Storage and managed disks for VMs for a full list of page blob supported tiers. 对于块 blob,在 blob 存储或常规用途 v2 帐户上受支持,仅限版本2018-11-09 和更高版本。For block blobs, supported on blob storage or general purpose v2 accounts only with version 2018-11-09 and newer. 块 blob 层的有效值为 Hot / Cool / ArchiveValid values for block blob tiers are Hot/Cool/Archive. 有关块 blob 分层的详细信息,请参阅热、冷和存档存储层For detailed information about block blob tiering see Hot, cool and archive storage tiers.

此操作还支持仅当满足指定条件时才使用条件标头写入 Blob。This operation also supports the use of conditional headers to write the blob only if a specified condition is met. 有关详细信息,请参阅为 Blob 服务操作指定条件标头For more information, see Specifying Conditional Headers for Blob Service Operations.

请求标头(仅限页 Blob)Request Headers (Page Blobs Only)

下表说明了仅适用于页 Blob 上的操作的请求标头。The following table describes request headers applicable only for operations on page blobs.

请求标头Request header 说明Description
x-ms-blob-content-length: bytes 对于页 Blob 是必需项。Required for page blobs. 此标头指定页 blob 的最大大小(最大为8个 TiB)。This header specifies the maximum size for the page blob, up to 8 TiB. 页 Blob 大小必须对齐 512 字节边界。The page blob size must be aligned to a 512-byte boundary.

如果为块 blob 或追加 blob 指定了此标头,Blob 服务将返回状态代码400(错误请求)。If this header is specified for a block blob or an append blob, the Blob service returns status code 400 (Bad Request).
x-ms-blob-sequence-number: <num> 可选。Optional. 仅对页 Blob 设置。Set for page blobs only. 序列号是一个用户控制的值,可以用来跟踪请求。The sequence number is a user-controlled value that you can use to track requests. 序列号的值必须介于 0 和 2^63 - 1 之间。默认值为 0。The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.
x-ms-access-tier 版本2017-04-17 和更高版本。Version 2017-04-17 and newer. 仅适用于高级存储帐户的页 blob。For page blobs on a premium storage account only. 指定要在 blob 上设置的层。Specifies the tier to be set on the blob. 查看vm 的高性能高级存储和托管磁盘,获取受支持的层的完整列表。Check High-performance Premium Storage and managed disks for VMs for a full list of supported tiers.
x-ms-client-request-id 此标头可用于排查请求和相应的响应。This header can be used to troubleshoot requests and corresponding responses. 如果此标头的值 x-ms-client-request-id 在请求中存在,并且其值最多为1024,则为该标头的值。The value of this header is equal to the value of the x-ms-client-request-id header if it is present in the request and the value is at most 1024 visible ASCII characters. 如果 x-ms-client-request-id 请求中不存在该标头,则此标头将不会出现在响应中。If the x-ms-client-request-id header is not present in the request, this header will not be present in the response.

请求标头(客户提供的加密密钥)Request Headers (Customer-provided encryption keys)

从版本2019-02-02 开始,可以在请求中指定以下标头,以使用客户提供的密钥来加密 blob。Beginning with version 2019-02-02, the following headers may be specified on the request to encrypt a blob with a customer-provided key. 使用客户提供的密钥(以及相应的标头集)进行加密是可选的。Encryption with a customer-provided key (and the corresponding set of headers) is optional.

请求标头Request header 说明Description
x-ms-encryption-key 必需。Required. Base64 编码的256加密密钥。The Base64-encoded AES-256 encryption key.
x-ms-encryption-key-sha256 必需。Required. 加密密钥的 Base64 编码的 SHA256 哈希。The Base64-encoded SHA256 hash of the encryption key.
x-ms-encryption-algorithm: AES256 必需。Required. 指定用于加密的算法。Specifies the algorithm to use for encryption. 此标头的值必须是 AES256The value of this header must be AES256.

请求正文Request Body

对于块 Blob,请求正文包含 Blob 的内容。For a block blob, the request body contains the content of the blob.

对于页 blob 或追加 blob,请求正文为空。For a page blob or an append blob, the request body is empty.

示例请求Sample Request

下面的示例是一个创建块 Blob 的请求:The following example shows a request to create a block blob:

Request Syntax:  
PUT https://myaccount.blob.core.windows.net/mycontainer/myblockblob HTTP/1.1  
  
Request Headers:  
x-ms-version: 2015-02-21  
x-ms-date: <date>  
Content-Type: text/plain; charset=UTF-8  
x-ms-blob-content-disposition: attachment; filename="fname.ext"  
x-ms-blob-type: BlockBlob  
x-ms-meta-m1: v1  
x-ms-meta-m2: v2  
Authorization: SharedKey myaccount:YhuFJjN4fAR8/AmBrqBz7MG2uFinQ4rkh4dscbj598g=  
Content-Length: 11  
  
Request Body:  
hello world  
  

此示例请求创建一个页 Blob 并为其指定最大大小 1024 字节。This sample request creates a page blob and specifies its maximum size as 1024 bytes. 请注意,必须调用Put 页,才能向页 blob 添加内容:Note that you must call Put Page to add content to a page blob:

Request Syntax:  
PUT https://myaccount.blob.core.windows.net/mycontainer/mypageblob HTTP/1.1  
  
Request Headers:  
x-ms-version: 2015-02-21  
x-ms-date: <date>  
Content-Type: text/plain; charset=UTF-8  
x-ms-blob-type: PageBlob  
x-ms-blob-content-length: 1024  
x-ms-blob-sequence-number: 0  
Authorization: SharedKey   
Origin: http://contoso.com  
Vary: Origin  
myaccount:YhuFJjN4fAR8/AmBrqBz7MG2uFinQ4rkh4dscbj598g=  
Content-Length: 0  

此示例请求创建追加 blob。This sample request creates an append blob. 请注意,必须调用追加块以将内容添加到追加 blob:Note that you must call Append Block to add content to the append blob:

Request Syntax:  
PUT https://myaccount.blob.core.windows.net/mycontainer/myappendblob HTTP/1.1  
  
Request Headers:  
x-ms-version: 2015-02-21  
x-ms-date: <date>  
Content-Type: text/plain; charset=UTF-8  
x-ms-blob-type: AppendBlob  
Authorization: SharedKey myaccount:YhuFJjN4fAR8/AmBrqBz7MG2uFinQ4rkh4dscbj598g=  
Origin: http://contoso.com  
Vary: Origin  
Content-Length: 0  
  

响应Response

响应包括 HTTP 状态代码和一组响应标头。The response includes an HTTP status code and a set of response headers.

状态代码Status Code

此操作成功后返回状态代码 201(已创建)。A successful operation returns status code 201 (Created).

有关状态代码的信息,请参阅状态和错误代码For information about status codes, see Status and Error Codes.

响应标头Response Headers

此操作的响应包括以下标头。The response for this operation includes the following headers. 响应还可以包括其他标准 HTTP 标头。The response can also include additional standard HTTP headers. 所有标准标头都符合HTTP/1.1 协议规范All standard headers conform to the HTTP/1.1 protocol specification.

响应标头Response header 说明Description
ETag ETag 包含一个值,客户端可以使用该值通过 PUT 请求标头执行条件 If-Match 操作。The ETag contains a value that the client can use to perform conditional PUT operations by using the If-Match request header. 如果请求版本为 2011-08-18 和更高版本,ETag 值将用引号引起来。If the request version is 2011-08-18 or newer, the ETag value will be in quotes.
Last-Modified 上次修改 Blob 的日期/时间。The date/time that the blob was last modified. 日期格式遵循 RFC 1123。The date format follows RFC 1123. 有关详细信息,请参阅标头中的日期时间值表示形式For more information, see Representation of Date-Time Values in Headers.

针对 Blob 的任何写操作(包括更新 Blob 的元数据或属性)都会更改 Blob 的上次修改时间。Any write operation on the blob (including updates on the blob's metadata or properties) changes the last modified time of the blob.
Content-MD5 针对块 Blob 返回此标头,以便客户端检查消息内容完整性。This header is returned for a block blob so the client can check the integrity of message content. 返回的 Content-MD5 值是由 BLOB 服务计算的。The Content-MD5 value returned is computed by the Blob service. 在版本 2012-02-12 和更新版本中,即使请求不包括 Content-MD5x-ms-blob-content-md5 标头,也会返回此标头。In version 2012-02-12 and later, this header is returned even when the request does not include Content-MD5 or x-ms-blob-content-md5 headers.
x-ms-content-crc64 针对块 Blob 返回此标头,以便客户端检查消息内容完整性。This header is returned for a block blob so the client can check the integrity of message content. 返回的 x-ms-content-crc64 值是由 BLOB 服务计算的。The x-ms-content-crc64 value returned is computed by the Blob service. 从版本2019-02-02 开始,将始终返回此标头。This header will always be returned starting from version 2019-02-02.
x-ms-request-id 此标头唯一地标识发出的请求,并且可用于解决请求问题。This header uniquely identifies the request that was made and can be used for troubleshooting the request. 有关详细信息,请参阅API 操作故障排除For more information, see Troubleshooting API Operations.
x-ms-version 指示用于执行请求的 BLOB 服务的版本。Indicates the version of the Blob service used to execute the request. 针对 2009-09-19 和更高版本发出的请求将返回此标头。This header is returned for requests made against version 2009-09-19 and later.
Date 服务生成的 UTC 日期/时间值指示启动响应的时间。A UTC date/time value generated by the service that indicates the time at which the response was initiated.
Access-Control-Allow-Origin 如果请求包含 Origin 标头并且通过匹配的规则启用了 CORS,则返回此标头。Returned if the request includes an Origin header and CORS is enabled with a matching rule. 如果存在匹配项,此标头返回原始请求标头的值。This header returns the value of the origin request header in case of a match.
Access-Control-Expose-Headers 如果请求包含 Origin 标头并且通过匹配的规则启用了 CORS,则返回此标头。Returned if the request includes an Origin header and CORS is enabled with a matching rule. 返回将向客户端或请求的发出方公开的响应标头的列表。Returns the list of response headers that are to be exposed to the client or issuer of the request.
Access-Control-Allow-Credentials 如果请求包含 Origin 标头并且通过不允许全部来源的匹配规则启用了 CORS,则返回此标头。Returned if the request includes an Origin header and CORS is enabled with a matching rule that does not allow all origins. 此标头将设置为 True。This header will be set to true.
x-ms-request-server-encrypted: true/false 版本2015-12-11 或更高版本。Version 2015-12-11 or newer. true如果使用指定的算法成功加密请求的内容,则将此标头的值设置为 false ; 否则设置为。The value of this header is set to true if the contents of the request are successfully encrypted using the specified algorithm, and false otherwise.
x-ms-encryption-key-sha256 版本2019-02-02 或更高版本。Version 2019-02-02 or newer. 如果请求使用客户提供的密钥进行加密,则返回此标头,以便客户端可以使用所提供的密钥来确保成功加密请求的内容。This header is returned if the request used a customer-provided key for encryption, so the client can ensure the contents of the request are successfully encrypted using the provided key.
x-ms-encryption-scope 版本2019-02-02 或更高版本。Version 2019-02-02 or newer. 如果请求使用加密范围,则返回此标头,以便客户端能够确保使用加密范围成功加密请求的内容。This header is returned if the request used an encryption scope, so the client can ensure the contents of the request are successfully encrypted using the encryption scope.
x-ms-version-id: <DateTime> 版本2019-12-12 和更高版本。Version 2019-12-12 and newer. 此标头返回 DateTime 唯一标识 blob 的不透明值。This header returns an opaque DateTime value that uniquely identifies the blob. 此标头的值指示 blob 的版本,可用于后续请求中以访问 blob。The value of this header indicates the Version of the blob, and may be used in subsequent requests to access the blob.

响应正文Response Body

无。None.

示例响应Sample Response

Response Status:  
HTTP/1.1 201 Created  
  
Response Headers:  
Transfer-Encoding: chunked  
Content-MD5: sQqNsWTgdUEFt6mb5y4/5Q==  
x-ms-content-crc64: 77uWZTolTHU
Date: <date>  
ETag: "0x8CB171BA9E94B0B"  
Last-Modified: <date>  
Access-Control-Allow-Origin: http://contoso.com  
Access-Control-Expose-Headers: Content-MD5  
Access-Control-Allow-Credentials: True  
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0  
x-ms-version-id: <DateTime>  

授权Authorization

此操作可由帐户所有者调用执行,也可由有权向此 Blob 或其容器写入数据并具有共享访问签名的任何客户端执行。This operation can be called by the account owner and by any client with a shared access signature that has permission to write to this blob or its container.

如果请求指定带有 x-ms-tags 请求标头的标记,则调用方必须满足 "设置 Blob 标记" 操作的授权要求。If a request specifies tags with the x-ms-tags request header, the caller must meet the authorization requirements of the Set Blob Tags operation.

注解Remarks

创建 blob 时,必须通过指定标头的值来指定它是否为块 blob、追加 blob 或页 blob x-ms-blob-typeWhen you create a blob, you must specify whether it is a block blob, append blob, or page blob by specifying the value of the x-ms-blob-type header. Blob 创建后,除非删除或重新创建,否则不能修改 Blob 类型。Once a blob has been created, the type of the blob cannot be changed unless it is deleted and re-created.

通过为版本2016-05-31 和更高版本创建的块 blob 的最大大小 Put Blob 为 256 mib,较旧版本为 64 mib。The maximum size for a block blob created via Put Blob is 256 MiB for version 2016-05-31 and later, and 64 MiB for older versions. 如果 blob 大于 256 MiB,适用于版本2016-05-31 和更高版本,或者针对较旧版本为 64 MiB,则必须将其上载为一组块。If your blob is larger than 256 MiB for version 2016-05-31 and later, or 64 MiB for older versions, you must upload it as a set of blocks. 有关详细信息,请参阅 Put BlockPut Block ListoperationsFor more information, see the Put Block and Put Block Listoperations. Put Blob如果以一组块的形式上传 blob,则无需调用。It's not necessary to also call Put Blob if you upload the blob as a set of blocks.

如果尝试为版本2016-05-31 和更高版本上载大于 256 MiB 的块 blob,64并为旧版本或大于 8 TiB 的页 blob 上载大于 MiB 的块 blob,则该服务将返回状态代码413(请求实体过大)。If you attempt to upload a block blob that is larger than 256 MiB for version 2016-05-31 and later, and 64 MiB for older versions, or a page blob larger than 8 TiB, the service returns status code 413 (Request Entity Too Large). BLOB 服务还会在响应中返回有关错误的详细信息,包括以字节数计的最大允许 Blob 大小。The Blob service also returns additional information about the error in the response, including the maximum blob size permitted in bytes.

若要创建新的页 blob,请先通过调用来初始化 blob, Put Blob 并指定其最大大小(最多8个 TiB)。To create a new page blob, first initialize the blob by calling Put Blob and specify its maximum size, up to 8 TiB. 创建页 Blob 时,不要在请求正文中包含内容。When creating a page blob, do not include content in the request body. 创建 blob 后,调用Put Page将内容添加到 blob 或修改 blob。Once the blob has been created, call Put Page to add content to the blob or to modify it.

若要创建新的追加 blob,请调用 Put Blob 创建内容长度为零字节的 blob。To create a new append blob, call Put Blob to create a blob with a content-length of zero bytes. 创建追加 blob 后,调用Append Block将内容添加到 blob 的末尾。Once the append blob is created, call Append Block to add content to the end of the blob.

如果调用Put Blob 覆盖具有相同名称的现有 Blob,将保留与原始 Blob 关联的所有快照。If you call Put Blob to overwrite an existing blob with the same name, any snapshots associated with the original blob are retained. 若要删除关联的快照,请先调用Delete blob ,然后再 Put Blob 重新创建 blob。To remove associated snapshots, call Delete Blob first, then Put Blob to re-create the blob.

Blob 具有自定义属性(通过头设置),可以用来存储与标准 HTTP 标头关联的值。A blob has custom properties (set via headers) that you can use to store values associated with standard HTTP headers. 随后可以通过调用获取 Blob 属性来读取这些值,也可以通过调用设置 blob 属性进行修改。These values can subsequently be read by calling Get Blob Properties, or modified by calling Set Blob Properties. 下表中列出了自定义属性头及相应的标准 HTTP 标头:The custom property headers and corresponding standard HTTP header are listed in the following table:

HTTP 标头HTTP header 自定义 Blob 属性头Custom blob property header
Content-Type x-ms-blob-content-type
Content-Encoding x-ms-blob-content-encoding
Content-Language x-ms-blob-content-language
Content-MD5 x-ms-blob-content-md5
Cache-Control x-ms-blob-cache-control

保持这些属性值和 Blob 的语义如下:The semantics for setting persisting these property values with the blob as follows:

  • 如果客户端指定自定义属性头,如由 x-ms-blob 前缀指示,则此值随 Blob 存储。If the client specifies a custom property header, as indicated by the x-ms-blob prefix, this value is stored with the blob.

  • 如果客户端指定标准 HTTP 标头,但未指定自定义属性头,则此值存储在与 Blob 关联的相应自定义属性中,由对Get Blob Properties的调用返回。If the client specifies a standard HTTP header, but not the custom property header, the value is stored in the corresponding custom property associated with the blob, and is returned by a call to Get Blob Properties. 例如,如果客户端对请求设置 Content-Type 标头,则该值存储在 Blob 的 x-ms-blob-content-type 属性中。For example, if the client sets the Content-Type header on the request, that value is stored in the blob's x-ms-blob-content-type property.

  • 如果客户端对同一请求既设置标准 HTTP 标头又设置相应的属性头,PUT 请求将使用为标准 HTTP 标头提供的值,为自定义属性头指定的值会与 Blob 一起保持并由随后的 GET 请求返回。If the client sets both the standard HTTP header and the corresponding property header on the same request, the PUT request uses the value provided for the standard HTTP header, but the value specified for the custom property header is persisted with the blob and returned by subsequent GET requests.

如果标头中提供标记 x-ms-tags ,则必须对其进行查询字符串编码。If tags are provided in the x-ms-tags header, they must be query-string encoded. 标记键和值必须符合设置 Blob 标记中指定的命名和长度要求。Tag keys and values must conform to the naming and length requirements as specified in Set Blob Tags. 此外,此 x-ms-tags 标头最多可包含2kb 个标记。Further, the x-ms-tags header may contain up to 2kb of tags. 如果需要更多标记,请使用 "设置 Blob 标记" 操作。If more tags are required, use the Set Blob Tags operation.

如果 Blob 具有活动租约,则客户端必须在请求中指定有效租约 ID 才能覆盖 Blob。If the blob has an active lease, the client must specify a valid lease ID on the request in order to overwrite the blob. 如果客户端不指定租约 ID,或指定无效的租约 ID,则 BLOB 服务将返回状态码 412(不满足前提条件)。If the client does not specify a lease ID, or specifies an invalid lease ID, the Blob service returns status code 412 (Precondition Failed). 如果客户端指定了一个租约 ID,但 Blob 没有活动租约,则 BLOB 服务也将返回状态码 412(不满足前提条件)。If the client specifies a lease ID but the blob does not have an active lease, the Blob service also returns status code 412 (Precondition Failed). 如果客户端对 Blob 指定的租约 ID 尚不存在,Blob 服务将对针对版本 2013-08-15 和更高版本提交的请求返回状态代码 412(不满足前提条件);对于以前的版本,Blob 服务将返回状态代码 201(已创建)。If the client specifies a lease ID on a blob that does not yet exist, the Blob service will return status code 412 (Precondition Failed) for requests made against version 2013-08-15 and later; for prior versions the Blob service will return status code 201 (Created).

如果Put Blob 操作覆盖了具有活动租约的现有 Blob,更新的 Blob 将保留租约,直至过期或释放。If an existing blob with an active lease is overwritten by a Put Blob operation, the lease persists on the updated blob, until it expires or is released.

Put Blob允许每个 MiB 10 分钟完成一次操作。A Put Blob operation is permitted 10 minutes per MiB to complete. 如果操作的每个 MiB 平均时间超过10分钟,则操作将超时。If the operation is taking longer than 10 minutes per MiB on average, the operation will timeout.

如果未提供 x ms 访问层标头,则覆盖已存档的 blob 将失败,并且覆盖 hot / cool blob 将从旧 blob 继承该层。Overwriting an archived blob will fail and overwriting a hot/cool blob will inherit the tier from the old blob if x-ms-access-tier header is not provided.

另请参阅See Also

向 Azure 存储授权请求 Authorize requests to Azure Storage
状态和错误代码 Status and Error Codes
Blob 服务错误代码 Blob Service Error Codes
为 Blob 服务操作设置超时Setting Timeouts for Blob Service Operations