Put Block List
The Put Block List
operation writes a blob by specifying the list of block IDs that make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior Put Block operation.
You can call Put Block List
to update a blob by uploading only those blocks that have changed, 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 may belong to.
Request
The Put Block List
request may be constructed as follows. HTTPS is recommended. 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 URI
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 Method Request URI | HTTP Version |
---|---|
http://127.0.0.1:10000/devstoreaccount1/mycontainer/myblob?comp=blocklist |
HTTP/1.1 |
Note that the storage emulator only supports blob sizes up to 2 GiB.
For more information, see Using the Azure Storage Emulator for Development and Testing.
URI Parameters
The following additional parameters may be specified on the request URI.
Parameter | Description |
---|---|
timeout |
Optional. The timeout parameter is expressed in seconds. For more information, see Setting Timeouts for Blob Service Operations. |
Request Headers
The following table describes required and optional request headers.
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. Note that 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 do not match, the operation will fail with error code 400 (Bad Request). Note that this header is associated with the request content, and not with the content of the blob itself. |
x-ms-content-crc64 |
Optional. An crc64 hash of the request content. This hash is used to verify the integrity of the request content during transport. If the two hashes do not match, the operation will fail with error code 400 (Bad Request). Note that 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 will fail with a 400 (Bad Request). This header is supported in versions2019-02-02 or later. |
x-ms-blob-cache-control |
Optional. Sets the blob’s cache control. If specified, this property is stored with the blob and returned with a read request. If this property is not specified with the request, then it is cleared for the blob if the request is successful. |
x-ms-blob-content-type |
Optional. Sets the blob’s content type. If specified, this property is stored with the blob and returned with a read request. If the content type is not specified, then it is set to the default type, which is application/octet-stream . |
x-ms-blob-content-encoding |
Optional. Sets the blob’s content encoding. If specified, this property is stored with the blob and returned with a read request. If this property is not specified with the request, then it is cleared for the blob if the request is successful. |
x-ms-blob-content-language |
Optional. Set the blob’s content language. If specified, this property is stored with the blob and returned with a read request. this property is not specified with the request, then it is cleared for the blob if the request is successful. |
x-ms-blob-content-md5 |
Optional. An MD5 hash of the blob content. Note that this hash is not validated, as 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 is not specified with the request, then it is cleared for the blob if the request is successful. |
x-ms-meta-name:value |
Optional. User-defined name-value pairs associated with the blob. 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 blob. This must match the encryption scope used to encrypt all the blocks that are being committed. This header is supported in versions 2019-02-02 or later. |
x-ms-tags |
Optional. Sets the given query-string encoded tags on the blob. See the Remarks for additional information. Supported in version 2019-12-12 and newer. |
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 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. For more information, see About Storage Analytics Logging and Azure Logging: Using Logs to Track Storage Requests. |
x-ms-blob-content-disposition |
Optional. Sets the blob’s Content-Disposition header. Available for versions 2013-08-15 and later.The Content-Disposition header field conveys additional information about how to process the response payload, and also can be used to attach additional metadata. For example, if set to attachment , it indicates that the user-agent should not display the response, but instead 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 newer. Indicates the tier to be set on a blob. For block blobs, supported on blob storage or general purpose v2 accounts only with version 2018-11-09 and newer. Valid values for block blob tiers are Hot /Cool /Archive . For detailed information about block blob tiering see Hot, cool and archive storage tiers. |
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 Specifying Conditional Headers for Blob Service Operations.
Request Headers (Customer-provided encryption keys)
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. 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 which block list the Blob service should check for the requested block. In this way you can update an existing blob by inserting, replacing, or deleting individual blocks, rather than re-uploading the entire blob. Once 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 wish 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 within the appropriate XML element within the request body, as follows:
Specify the block ID within the
Committed
element to indicate that the Blob service should search only the committed block list for the named block. If the block is not found in the committed block list, it will not be written as part of the blob, and the Blob service will return status code 400 (Bad Request).Specify the block ID within the
Uncommitted
element to indicate that the Blob service should search only the uncommitted block list for the named block. If the block is not found in the uncommitted block list, it will not be written as part of the blob, and the Blob service will return status code 400 (Bad Request).Specify the block ID within the
Latest
element to indicate that the Blob service 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 is not found in the uncommitted list, then the service should search the committed block list for the named block and write that block to the blob if it is found.
The request body for this version of Put Block List
uses 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 wish 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, assume that you wish to update the blob. The new blob will have the following changes:
A new block with ID
ANAAAA==
. This block must first be uploaded with a call to Put Block and will appear in the uncommitted block list until the call toPut Block List
.An updated version of the block with ID
AZAAAA==
. This block must first be uploaded with a call to Put Block and will appear in the uncommitted block list until the call toPut Block List
.Removal of the block with the ID
AAAAAA==
. Given that this block is not included in the next call toPut Block List
, the block will effectively be 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
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 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 newer, the ETag value will be in quotes. |
Last-Modified |
The date/time that the blob was last modified. The date format follows RFC 1123. For more information, see Representation of 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 |
This header is returned so that the client can check for message content integrity. This header refers to the content of the request, meaning, in this case, the list of blocks, and not the content of the blob itself. For versions2019-02-02 or later, This header is only returned when the request has this header. |
x-ms-content-crc64 |
For versions 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, meaning, in this case, the list of blocks, and not the content of the blob itself. This header is returned when Content-md5 header is not present in the request. |
x-ms-request-id |
This header uniquely identifies the request that was made and can be used for troubleshooting the request. For more information, see Troubleshooting API Operations. |
x-ms-version |
Indicates the version of the Blob service used to execute the request. This header is returned for requests made against version 2009-09-19 and later. |
Date |
A UTC date/time value generated by the service that indicates the time at which the response was initiated. |
x-ms-request-server-encrypted: true/false |
Version 2015-12-11 or newer. 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 |
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 |
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> |
Version 2019-12-12 and newer. This header returns an opaque DateTime value that uniquely identifies the blob. The value of this header indicates the version of the blob, and may be used in subsequent requests to access the blob. |
x-ms-client-request-id |
This header can be used to troubleshoot requests and corresponding responses. 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. If the x-ms-client-request-id header is not present in the request, this header will not be 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
This operation can be called by the account owner and by anyone with a Shared Access Signature that has permission to write to this blob or its container.
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
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 will represent 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 uploading 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, then Put Block List
commits the block from the committed block list.
Each block can be a different size, up to a maximum of 4000 MiB for version 2019-12-12 and later (Preview), 100 MiB for version 2016-05-31 and later, and 4 MiB for older versions. The maximum size of a block blob is therefore 190.7 TiB (4000 MiB X 50,000 blocks) for version 2019-12-12 and later (Preview), 4.75 TiB (100 MiB X 50,000 blocks) for version 2016-05-31 and later, and 195 GiB (4 MiB X 50,000 blocks) for all older versions. If you attempt to commit more than 50,000 blocks, the service returns status code 400 (Block List Too Long). The service also returns additional information about the error in the response, including the maximum number of blocks permitted.
The maximum number of uncommitted blocks that may be associated with a blob is 100,000.
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 due to a missing block, you will need to upload the missing block.
Any uncommitted blocks will be 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 will be 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 up to 2kb of tags. 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 in order to commit the block list. If the client does not specify a lease ID, or specifies an invalid lease ID, the Blob service returns status code 412 (Precondition Failed). 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). 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).
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 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
Understanding Block Blobs, Append Blobs, and Page Blobs
Authorize requests to Azure Storage
Status and Error Codes
Blob Service Error Codes
Setting Timeouts for Blob Service Operations