Κοινή χρήση μέσω


Put Block List

The Put Block List operation writes a blob by specifying the list of block IDs that make up the blob. To be written as part of a blob, a block must have been successfully written to the server in an earlier Put Block operation.

You can call Put Block List to update a blob by uploading only those blocks that have changed and then committing the new and existing blocks together. You can do this by specifying whether to commit a block from the committed block list or from the uncommitted block list, or to commit the most recently uploaded version of the block, whichever list it belongs to.

Request

You can construct the Put Block List request as follows. We recommend that you use HTTPS. Replace myaccount with the name of your storage account:

PUT method request URI HTTP version
https://myaccount.blob.core.windows.net/mycontainer/myblob?comp=blocklist HTTP/1.1

Emulated storage service request

When you're 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 method request URI HTTP version
http://127.0.0.1:10000/devstoreaccount1/mycontainer/myblob?comp=blocklist HTTP/1.1

The storage emulator supports blob sizes of up to 2 gibibytes (GiB) only.

For more information, see Use the Azurite emulator for local Azure Storage development.

URI parameters

You can specify the following additional parameters on the request URI:

Parameter Description
timeout Optional. The timeout parameter is expressed in seconds. For more information, see Set time-outs for Blob service operations.

Request headers

The required and optional request headers are described in the following table:

Request header Description
Authorization Required. Specifies the authorization scheme, account name, and signature. For more information, see Authorize requests to Azure Storage.
Date or x-ms-date Required. Specifies the Coordinated Universal Time (UTC) for the request. 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. For more information, see Versioning for the Azure Storage services.
Content-Length Required. The length of the request content, in bytes. This header refers to the content length of the list of blocks, not of the blob itself.
Content-MD5 Optional. An MD5 hash of the request content. This hash is used to verify the integrity of the request content during transport. If the two hashes don't match, the operation fails with error code 400 (Bad Request).

This header is associated with the request content, and not with the content of the blob itself.
x-ms-content-crc64 Optional. A CRC64 hash of the request content. This hash is used to verify the integrity of the request content during transport. If the two hashes don't match, the operation fails with error code 400 (Bad Request).

This header is associated with the request content, and not with the content of the blob itself.

If both Content-MD5 and x-ms-content-crc64 headers are present, the request fails with a 400 (Bad Request).

This header is supported in version 2019-02-02 and later.
x-ms-blob-cache-control Optional. Sets the blob’s cache control. If this property is specified, it's stored with the blob and returned with a read request.

If the property isn't specified with the request, it's cleared for the blob if the request is successful.
x-ms-blob-content-type Optional. Sets the blob’s content type. If it's specified, this property is stored with the blob and returned with a read request.

If the content type isn't specified, it's set to the default type, which is application/octet-stream.
x-ms-blob-content-encoding Optional. Sets the blob’s content encoding. If it's specified, this property is stored with the blob and returned with a read request.

If the property isn't specified with the request, it's cleared for the blob if the request is successful.
x-ms-blob-content-language Optional. Sets the blob’s content language. If it's specified, this property is stored with the blob and returned with a read request.

If the property isn't specified with the request, it's cleared for the blob if the request is successful.
x-ms-blob-content-md5 Optional. An MD5 hash of the blob content. This hash isn't validated, because the hashes for the individual blocks were validated when each was uploaded.

The Get Blob operation returns the value of this header in the Content-MD5 response header.

If this property isn't specified with the request, it's cleared for the blob if the request is successful.
x-ms-meta-name:value Optional. User-defined name-value pairs that are associated with the blob.

As of 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 blob. This value must match the encryption scope that's used to encrypt all the blocks that are being committed. This header is supported in version 2019-02-02 and later.
x-ms-encryption-context Optional. Default is “Empty”. If the value is set it will set blob system metadata. Max length-1024. Valid only when Hierarchical Namespace is enabled for the account. This header is supported in versions 2021-08-06 and later.
x-ms-tags Optional. Sets the specified query-string encoded tags on the blob. For additional information, see the Remarks section. Supported in version 2019-12-12 and later.
x-ms-lease-id:<ID> Required if the blob has an active lease. To perform this operation on a blob with an active lease, specify the valid lease ID for this header.
x-ms-client-request-id Optional. Provides a client-generated, opaque value with a 1-kibibyte (KiB) character limit that's recorded in the analytics logs when storage analytics logging is configured. We highly recommend that you use this header to correlate client-side activities with requests that the server receives.
x-ms-blob-content-disposition Optional. Sets the blob’s Content-Disposition header. Available for version 2013-08-15 and later.

The Content-Disposition header field conveys additional information about how to process the response payload, and it can be used to attach additional metadata. For example, if it's set to attachment, this header indicates that the user-agent should not display the response, but instead should show a Save As dialog.

The response from the Get Blob and Get Blob Properties operations includes the content-disposition header.
x-ms-access-tier Optional. Version 2018-11-09 and later. Indicates the tier to be set on a blob. For block blobs, this header is supported on blob storage or general purpose v2 accounts only with version 2018-11-09 and later. Valid values for block blob tiers are Hot, Cool, Cold, and Archive. Note: Cold tier is supported for version 2021-12-02 and later. For detailed information about block blob tiering see Hot, cool, and archive storage tiers.
x-ms-immutability-policy-until-date Version 2020-06-12 and later. Specifies the retention-until date to be set on the blob. This is the date until which the blob can be protected from being modified or deleted. Follows RFC1123 format.
x-ms-immutability-policy-mode Version 2020-06-12 and later. Specifies the immutability policy mode to be set on the blob. Valid values are unlocked and locked. The unlocked value indicates that users can change the policy by increasing or decreasing the retention-until date. The locked value indicates that these actions are prohibited.
x-ms-legal-hold Version 2020-06-12 and later. Specifies the legal hold to be set on the blob. The valid values are true and false.
x-ms-expiry-option Optional. Version 2023-08-03 and later. Specifies the expiration date option for the request, see ExpiryOption. This header is valid for accounts with hierarchical namespace enabled.
x-ms-expiry-time Optional. Version 2023-08-03 and later. Specifies the time when the blob is set to expire. The format for expiration date varies according to x-ms-expiry-option. For more information, see ExpiryOption. This header is valid for accounts with hierarchical namespace enabled.

The expiryTime already present on a blob is not cleared if the request doesn't contain a new value of expiryTime

This operation also supports the use of conditional headers to commit the block list only if a specified condition is met. For more information, see Specify conditional headers for Blob Storage operations.

Request headers (customer-provided encryption keys)

As of version 2019-02-02, you can specify the following headers 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. The Base64-encoded AES-256 encryption key.
x-ms-encryption-key-sha256 Required. The Base64-encoded SHA256 hash of the encryption key.
x-ms-encryption-algorithm: AES256 Required. Specifies the algorithm to use for encryption. The value of this header must be AES256.

Request body

In the request body, you can specify the block list that Blob Storage should check for the requested block. In this way, you can update an existing blob by inserting, replacing, or deleting individual blocks, rather than reuploading the entire blob. After you've uploaded the block or blocks that have changed, you can commit a new version of the blob by committing the new blocks together with the existing blocks that you want to keep.

To update a blob, you can specify that the service should look for a block ID in the committed block list, in the uncommitted block list, or in the uncommitted block list first and then in the committed block list. To indicate which approach to use, specify the block ID that's within the appropriate XML element within the request body, as follows:

  • Specify the block ID within the Committed element to indicate that Blob Storage should search only the committed block list for the named block. If the block isn't found in the committed block list, it isn't written as part of the blob, and Blob Storage returns status code 400 (Bad Request).

  • Specify the block ID within the Uncommitted element to indicate that Blob Storage should search only the uncommitted block list for the named block. If the block isn't found in the uncommitted block list, it isn't written as part of the blob, and Blob Storage returns status code 400 (Bad Request).

  • Specify the block ID within the Latest element to indicate that Blob Storage should first search the uncommitted block list. If the block is found in the uncommitted list, that version of the block is the latest and should be written to the blob. If the block isn't found in the uncommitted list, the service should search the committed block list for the named block and write that block to the blob if it's found.

The request body for this version of Put Block List uses the following XML format:

<?xml version="1.0" encoding="utf-8"?>  
<BlockList>  
  <Committed>first-base64-encoded-block-id</Committed>  
  <Uncommitted>second-base64-encoded-block-id</Uncommitted>  
  <Latest>third-base64-encoded-block-id</Latest>  
  ...  
</BlockList>  
  

Sample request

To demonstrate Put Block List, assume you have uploaded three blocks that you now want to commit. The following example commits a new blob by indicating that the latest version of each block listed should be used. It's not necessary to know whether these blocks have already been committed.

Request Syntax:  
PUT https://myaccount.blob.core.windows.net/mycontainer/myblob?comp=blocklist HTTP/1.1  
  
Request Headers:  
x-ms-date: Wed, 31 Aug 2011 00:17:43 GMT  
x-ms-version: 2011-08-18  
Content-Type: text/plain; charset=UTF-8  
Authorization: SharedKey myaccount:DJ5QZSVONZ64vAhnN/wxcU+Pt5HQSLAiLITlAU76Lx8=  
Content-Length: 133  
  
Request Body:  
<?xml version="1.0" encoding="utf-8"?>  
<BlockList>  
  <Latest>AAAAAA==</Latest>  
  <Latest>AQAAAA==</Latest>  
  <Latest>AZAAAA==</Latest>  
</BlockList>  
  

Next, let's assume that you want to update the blob. The new blob has the following changes:

  • A new block with ID ANAAAA==. This block must first be uploaded with a call to Put Block, and it appears in the uncommitted block list until the call to Put Block List.

  • An updated version of the block with ID AZAAAA==. This block must first be uploaded with a call to Put Block, and it appears in the uncommitted block list until the call to Put Block List.

  • Removal of the block with the ID AAAAAA==. Because this block isn't included in the next call to Put Block List, the block is effectively removed from the blob.

The following example shows the call to Put Block List that updates the blob:

Request Syntax:  
PUT https://myaccount.blob.core.windows.net/mycontainer/myblob?comp=blocklist HTTP/1.1  
  
Request Headers:  
x-ms-date: Wed, 31 Aug 2009 00:17:43 GMT  
x-ms-version: 2011-08-18  
Content-Type: text/plain; charset=UTF-8  
x-ms-expiry-option: RelativeToNow
x-ms-expiry-time: 30000
Authorization: SharedKey myaccount:DJ5QZSVONZ64vAhnN/wxcU+Pt5HQSLAiLITlAU76Lx8=  
Content-Length: 133  
  
Request Body:  
<?xml version="1.0" encoding="utf-8"?>  
<BlockList>  
  <Uncommitted>ANAAAA==</Uncommitted>  
  <Committed>AQAAAA==</Committed>  
  <Uncommitted>AZAAAA==</Uncommitted>  
</BlockList>  
  

Response

The response includes an HTTP status code and a set of response headers.

Status code

A successful operation returns status code 201 (Created).

For more information about status codes, see Status and error codes.

Response headers

The response for this operation includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.

Response Descriptions
ETag The entity tag contains a value that the client can use to perform conditional GET/PUT operations by using the If-Match request header. If the request version is 2011-08-18 or later, the ETag value is enclosed in quotation marks.
Last-Modified The date/time that the blob was last modified. The date format follows RFC 1123. For more information, see Represent date/time values in headers.

Any operation that modifies the blob, including an update of the blob's metadata or properties, changes the last modified time of the blob.
Content-MD5 Returned so that the client can check for message content integrity. This header refers to the content of the request (in this case, the list of blocks and not the content of the blob itself). For version 2019-02-02 and later, this header is returned only when the request has this header.
x-ms-content-crc64 For version 2019-02-02 and later, this header is returned so that the client can check for message content integrity. This header refers to the content of the request (in this case, the list of blocks and not the content of the blob itself).

This header is returned when Content-md5 header isn't present in the request.
x-ms-request-id Uniquely identifies the request that was made, and you can use it to troubleshoot the request. For more information, see Troubleshoot API operations.
x-ms-version The version of Blob Storage that's used to execute the request. This header is returned for requests that are made against version 2009-09-19 and later.
Date A UTC date/time value that's generated by the service, which indicates when the response was initiated.
x-ms-request-server-encrypted: true/false Version 2015-12-11 and later. The value of this header is set to true if the contents of the request are successfully encrypted using the specified algorithm. Otherwise, the value is set to false.
x-ms-encryption-key-sha256 Version 2019-02-02 and later. This header is returned if the request used a customer-provided key for encryption, so the client can ensure that the contents of the request are successfully encrypted by using the provided key.
x-ms-encryption-scope Version 2019-02-02 and later. This header is returned if the request used an encryption scope, so the client can ensure that the contents of the request are successfully encrypted by using the encryption scope.
x-ms-version-id: <DateTime> Version 2019-12-12 and later. Returns an opaque DateTime value that uniquely identifies the blob. The value of this header indicates the version of the blob, and it can be used in subsequent requests to access the blob.
x-ms-client-request-id Can be used to troubleshoot requests and their corresponding responses. The value of this header is equal to the value of the x-ms-client-request-id header if it's present in the request and the value contains no more than 1,024 visible ASCII characters. If the x-ms-client-request-id header isn't present in the request, it isn't present in the response.

Sample response

Response Status:  
HTTP/1.1 201 Created  
  
Response Headers:  
Transfer-Encoding: chunked  
x-ms-content-crc64: 77uWZTolTHU  
Date: Sun, 25 Sep 2011 00:17:44 GMT  
ETag: “0x8CB172A360EC34B”  
Last-Modified: Sun, 25 Sep 2011 00:17:43 GMT  
x-ms-version: 2011-08-18  
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0  
x-ms-version-id: <DateTime>  

Authorization

Authorization is required when calling any data access operation in Azure Storage. You can authorize the Put Block List operation as described below.

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.

Important

Microsoft recommends using Microsoft Entra ID with managed identities to authorize requests to Azure Storage. Microsoft Entra ID provides superior security and ease of use compared to Shared Key authorization.

Azure Storage supports using Microsoft Entra ID to authorize requests to blob data. With Microsoft Entra ID, you can use Azure role-based access control (Azure RBAC) to grant permissions to a security principal. The security principal may be a user, group, application service principal, or Azure managed identity. The security principal is authenticated by Microsoft Entra ID to return an OAuth 2.0 token. The token can then be used to authorize a request against the Blob service.

To learn more about authorization using Microsoft Entra ID, see Authorize access to blobs using Microsoft Entra ID.

Permissions

Listed below are the RBAC action necessary for a Microsoft Entra user, group, managed identity, or service principal to call the Put Block List operation, and the least privileged built-in Azure RBAC role that includes this action:

To learn more about assigning roles using Azure RBAC, see Assign an Azure role for access to blob data.

Remarks

The Put Block List operation enforces the order in which blocks are to be combined to create a blob.

The same block ID can be specified more than one time in the list of blocks. If a block ID is specified more than one time, it represents the range of bytes in each of those locations in the block list for the final committed blob. If a block ID appears more than once in the list, both instances of the block ID must be specified within the same block list. In other words, both instances must be specified within the Committed element, the Uncommitted element, or the Latest element.

With Put Block List, you can modify an existing blob by inserting, updating, or deleting individual blocks without having to upload the whole blob again. You can specify block IDs from both the current committed block list and the uncommitted block list to create a new blob or update the content of an existing blob. In this way, you can update a blob by specifying a few new blocks from the uncommitted block list, and the rest from the committed block list, which are already part of the existing blob.

If a block ID is specified in the Latest element, and the same block ID exists in both the committed and uncommitted block lists, Put Block List commits the block from the uncommitted block list. If the block ID exists in the committed block list but not in the uncommitted block list, Put Block List commits the block from the committed block list.

Each block in a block blob can be a different size. A block blob can include a maximum of 50,000 committed blocks. The maximum number of uncommitted blocks that may be associated with a blob is 100,000.

The following table describes the maximum permitted block and blob sizes, by service version:

Service version Maximum block size (via Put Block) Maximum blob size (via Put Block List) Maximum blob size via single write operation (via Put Blob)
Version 2019-12-12 and later 4,000 mebibytes (MiB) Approximately 190.7 tebibytes (TiB) (4,000 MiB × 50,000 blocks) 5,000 MiB
Versions 2016-05-31 through 2019-07-07 100 MiB Approximately 4.75 TiB (100 MiB × 50,000 blocks) 256 MiB
Versions earlier than 2016-05-31 4 MiB Approximately 195 GiB (4 MiB × 50,000 blocks) 64 MiB

When you call Put Block List to update an existing blob, the blob's existing properties and metadata are overwritten. However, any existing snapshots are retained with the blob. You can use the conditional request headers to perform the operation only if a specified condition is met.

If the Put Block List operation fails because of a missing block, you need to upload the missing block.

Any uncommitted blocks are garbage collected if there are no successful calls to Put Block or Put Block List on the blob within a week following the last successful Put Block operation. If Put Blob is called on the blob, any uncommitted blocks are garbage collected.

If tags are provided in the x-ms-tags header, they must be query-string encoded. Tag keys and values must conform to the naming and length requirements, as specified in Set Blob Tags. Further, the x-ms-tags header may contain tags of up to 2 KiB in size. If more tags are required, use the Set Blob Tags operation.

If the blob has an active lease, the client must specify a valid lease ID on the request to commit the block list. If the client either doesn't specify a lease ID or specifies an invalid lease ID, Blob Storage returns status code 412 (Precondition Failed). If the client specifies a lease ID but the blob doesn't have an active lease, Blob Storage also returns status code 412 (Precondition Failed). If the client specifies a lease ID on a blob that doesn't yet exist, Blob Storage returns status code 412 (Precondition Failed) for requests made against version 2013-08-15 or later. For earlier versions, Blob Storage returns status code 201 (Created).

If the blob has an active lease and you call Put Block List to update the blob, the lease is maintained on the updated blob.

Put Block List applies only to block blobs. Calling Put Block List on a page blob results in status code 400 (Bad Request).

Overwriting an archived blob fails, and overwriting a hot or cool blob inherits the tier from the old blob if the x-ms-access-tier header isn't provided.

Billing

Pricing requests can originate from clients that use Blob Storage APIs, either directly through the Blob Storage REST API, or from an Azure Storage client library. These requests accrue charges per transaction. The type of transaction affects how the account is charged. For example, read transactions accrue to a different billing category than write transactions. The following table shows the billing category for Put Block List requests based on the storage account type:

Operation Storage account type Billing category
Put Block List Premium block blob
Standard general-purpose v2
Standard general-purpose v1
Write operations

To learn about pricing for the specified billing category, see Azure Blob Storage Pricing.

See also

Understand block blobs, append blobs, and page blobs
Authorize requests to Azure Storage
Status and error codes
Blob service error codes
Set time-outs for Blob service operations