Поділитися через


Put Page

The Put Page operation writes a range of pages to a page blob.

Request

You can construct the Put Page 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=page 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=page HTTP/1.1

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.
Range Either Range or x-ms-range is required.

Specifies the range of bytes to be written as a page. Both the start and end of the range must be specified. This header is defined by the HTTP/1.1 protocol specification.

For a page update operation, the page range can be up to 4 MiB. For a page clear operation, the page range can be as great as the value of the blob's full size.

Because pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the end offset must be a modulus of 512 –1. Examples of valid byte ranges are 0-511, 512-1023, and so on.

Blob Storage accepts only a single byte range for the Range header, and the byte range must be specified in the following format: bytes=startByte-endByte.

If both Range and x-ms-range are specified, the service uses the value of x-ms-range. For more information, see Specify the range header for Blob service operations.
x-ms-range Either Range or x-ms-range is required.

Specifies the range of bytes to be written as a page. Both the start and end of the range must be specified. This header is defined by the HTTP/1.1 protocol specification.

For a page update operation, the page range can be as great as 4 MiB in size. For a page clear operation, the page range can be up to the value of the blob's full size.

Because pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the end offset must be a modulus of 512 – 1. Examples of valid byte ranges are 0-511, 512-1023, etc.

Blob Storage accepts only a single byte range for the x-ms-range header, and the byte range must be specified in the following format: bytes=startByte-endByte.

If both Range and x-ms-range are specified, the service uses the value of x-ms-range. See Specify the range header for Blob service operations for more information.
Content-Length Required. Specifies the number of bytes being transmitted in the request body. When the x-ms-page-write header is set to clear, the value of this header must be set to 0.
Content-MD5 Optional. An MD5 hash of the page content. This hash is used to verify the integrity of the page during transport. When this header is specified, the storage service compares the hash of the content that has arrived with this header value.
<br / > Note: This MD5 hash isn't stored with the blob.

If the two hashes don't match, the operation fails with error code 400 (Bad Request).
x-ms-content-crc64 Optional. A CRC64 hash of the page content. This hash is used to verify the integrity of the page during transport. When this header is specified, the storage service compares the hash of the content that has arrived with this header value.

Note: This CRC64 hash isn't stored with the blob.

If the two hashes don't match, the operation fails with error code 400 (Bad Request).

If both the 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-page-write: {update ¦ clear} Required. You can specify one of the following options:

- Update: Writes the bytes that are specified by the request body into the specified range. The Range and Content-Length headers must match to perform the update.
- Clear: Clears the specified range and releases the space that's used in storage for that range. To clear a range, set the Content-Length header to 0, and set the Range header to a value that indicates the range to clear, up to the maximum blob size.
x-ms-encryption-scope Optional. Indicates the encryption scope to use to encrypt the request contents. This header is supported in version 2019-02-02 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-if-sequence-number-le: <num> Optional. If the blob’s sequence number is less than or equal to the specified value, the request proceeds. Otherwise, it fails with the SequenceNumberConditionNotMet error (HTTP status code 412 – Precondition Failed).
x-ms-if-sequence-number-lt: <num> Optional. If the blob’s sequence number is less than the specified value, the request proceeds. Otherwise, it fails with SequenceNumberConditionNotMet error (HTTP status code 412 – Precondition Failed).
x-ms-if-sequence-number-eq: <num> Optional. If the blob’s sequence number is equal to the specified value, the request proceeds. Otherwise, it fails with SequenceNumberConditionNotMet error (HTTP status code 412 – Precondition Failed).
If-Modified-Since Optional. A DateTime value. Specify this conditional header to write the page only if the blob has been modified since the specified date/time. If the blob hasn't been modified, Blob Storage returns status code 412 (Precondition Failed).
If-Unmodified-Since Optional. A DateTime value. Specify this conditional header to write the page only if the blob hasn't been modified since the specified date/time. If the blob has been modified, Blob Storage returns status code 412 (Precondition Failed).
If-Match Optional. An ETag value. Specify an ETag value for this conditional header to write the page only if the blob's ETag value matches the value specified. If the values don't match, Blob Storage returns status code 412 (Precondition Failed).
If-None-Match Optional. An ETag value.

Specify an ETag value for this conditional header to write the page only if the blob's ETag value doesn't match the value specified. If the values are identical, Blob Storage returns status code 412 (Precondition Failed).
x-ms-client-request-id Optional. Provides a client-generated, opaque value with a 1-kibibyte (KiB) character limit that's recorded in the logs when logging is configured. We highly recommend that you use this header to correlate client-side activities with requests that the server receives. For more information, see Monitor Azure Blob Storage.

This operation also supports the use of conditional headers to execute the operation only if a specified condition is met. For more information, see Specify conditional headers for Blob service 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

The request body contains the content of the page.

Sample request: Update byte range

  
Request Syntax:  
PUT https://myaccount.blob.core.windows.net/mycontainer/myblob?comp=page HTTP/1.1  
  
Request Headers:  
x-ms-page-write: update  
x-ms-date: Fri, 16 Sep 2011 22:15:50 GMT  
x-ms-version: 2011-08-18  
x-ms-range: bytes=0-65535  
Authorization: SharedKey myaccount:4KdWDiTdA9HmIF9+WF/8WfYOpUrFhieGIT7f0av+GEI=  
Content-Length: 65536  
  

Sample request: Clear byte range

  
Request Syntax:  
PUT https://myaccount.blob.core.windows.net/mycontainer/myblob?comp=page HTTP/1.1  
  
Request Headers:  
Range: bytes=1024-2048  
x-ms-page-write: clear  
x-ms-date: Sun, 25 Sep 2011 23:37:35 GMT  
x-ms-version: 2011-08-18  
Authorization: SharedKey myaccount:4KdWDiTdA9HmIF9+WF/8WfYOpUrFhieGIT7f0av+GEI=  
  

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 can also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.

Syntax Description
ETag The ETag for the blob. If the request version is 2011-08-18 and later, the ETag value is enclosed in quotation marks. The ETag can be used to perform a conditional Put Page operation by specifying its value for the If-Match or If-None-Match request header.
Last-Modified The date and time when the blob was last modified. The date format follows RFC 1123. For more information, see Represent date/time values in headers.

Any write operation on the blob, including updates to 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. The value of this header is computed by Blob Storage. It's not necessarily the same as the value that's specified in the request headers. 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 or later, this header is returned so that the client can check for message content integrity. The value of this header is computed by Blob Storage. It's not necessarily the same as the value that's specified in the request headers.

This header is returned when Content-MD5 header isn't present in the request.
x-ms-blob-sequence-number The current sequence number for the page blob.
x-ms-request-id Uniquely identifies the request that was made, and it can be used to troubleshoot the request. For more information, see Troubleshoot API operations.
x-ms-version Indicates the Blob service version that was used to execute the request. This header is returned for requests that were made against version 2009-09-19 and later.
Date A UTC date/time value that's generated by the service, which indicates the time 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 by using the specified algorithm. Otherwise, the value is set to false.
x-ms-encryption-key-sha256 Version 2019-02-02 and later. 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. 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-client-request-id 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'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 won't be present in the response.

Response body

None.

Sample response

Response Status:  
HTTP/1.1 201 Created  
  
Response Headers:  
x-ms-content-crc64: 77uWZTolTHU  
Date: Sun, 25 Sep 2011 22:33:35 GMT  
ETag: "0x8CB171BA9E94B0B"  
Last-Modified: Sun, 25 Sep 2011 12:13:31 GMT  
x-ms-version: 2011-08-18  
x-ms-blob-sequence-number: 0  
Content-Length: 0  
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0  
  

Authorization

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

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 Page 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 Page operation writes a range of pages to a page blob. This operation can be called only on an existing page blob. It can't be called to create a new page blob, nor can it be called on a block blob. Calling Put Page with a blob name that doesn't currently exist returns HTTP status code 404 (Not Found).

To create a new page blob, call Put Blob and specify the type of blob to create as a page blob. A page blob can be up to 8 TiB in size.

If the blob has an active lease, the client must specify a valid lease ID on the request to write a page.

Page update operations

Calling Put Page with the Update option performs an in-place write on the specified page blob. Any content in the specified page is overwritten with the update.

Important

If the server times out or your connection is closed during a Put Page operation, the page might or might not have been updated. Therefore, you should continue to retry the update until you receive a response that indicates success.

Each range of pages that's submitted with Put Page for an update operation may be up to 4 MiB in size. The start and end range of the page must be aligned with 512-byte boundaries. If you attempt to upload a range of pages that's larger than 4 MiB, the service returns status code 413 (Request Entity Too Large).

Page clear operations

Calling Put Page with the Clear option releases the storage space that's used by the specified page. Pages that have been cleared are no longer tracked as part of the page blob.

Pages that have been cleared no longer incur a charge against the storage account, because their storage resources have been released. The only exception to this is if there are existing snapshots of the page blob. Pages in snapshots incur a charge if those same pages no longer exist as part of the source blob.

Manage concurrency issues

Blob Storage handles concurrent writes to overlapping pages sequentially. That is, the last page processed by the service determines the blob's content. Therefore, to ensure the integrity of the blob's content, the client should handle writes to overlapping pages by using one or more of the following approaches:

  • You can check the value of the Last-Modified response header for each successful call to Put Page. The order of responses returned from Blob Storage doesn't necessarily correspond to the order in which they were executed by the service. But the value of Last-Modified always indicates the order in which the service processed the requests.

  • You can perform updates conditionally based on the blob's ETag or last modified time using optimistic concurrency. This approach works well if the number of concurrent writes is relatively low. Use the conditional request headers If-Match, If-None-Match, If-Modified-Since, and If-Unmodified-Since for this purpose.

  • You can call Lease Blob to lock the blob against other writes for a one-minute period, or longer if the lease is renewed.

  • You can use the blob's sequence number to ensure that retrying a request for which there was no response doesn't result in concurrent updates. This approach may be best for clients that require high throughput for page writes. This is described in detail in the following section.

Use the page blob sequence number to retry requests

When a call to Put Page times out or doesn't return a response, there's no way to know for certain whether the request succeeded. You therefore need to retry the request but, because of the distributed nature of the Azure storage services, it's possible that the original request may be processed after the retried request has succeeded. The delayed original request can overwrite other updates and yield an unexpected result. The following sequence illustrates how this might happen:

  1. A Put Page request to write value "X" to page 0 times out or doesn't return a response.

  2. A retried request to write value "X" to page 0 succeeds.

  3. A request to write value "Y" to page 0 succeeds.

  4. The original request succeeds, writing value "X" to page 0.

  5. Reading page 0 returns value "X", when the client was at this point expecting value "Y".

This kind of conflict can occur when the original request doesn't return a status code from 100 to 499, or 503 (Server Busy). If one of these status codes is returned, you can be certain as to whether the request has succeeded or failed. But if the service returns a status code outside this range, there's no way to know the status of the original request.

To prevent this sort of conflict, you can use the page blob's sequence number to ensure that when you retry a request, the original request won't succeed. To do so, you should increment the sequence number before retrying the original request. You can then use the conditional sequence number headers to ensure that the request fails if its sequence number doesn't match the expected sequence number. The following sequence illustrates this approach:

  1. The client creates a page blob with Put Blob and sets its sequence number to 0.

  2. A Put Page request to write value "X" to page 0 with the if-sequence-number-lt header set to 1 times out or doesn't return a response.

  3. The client calls Set Blob Properties to update the sequence number to 1.

  4. A retried request to write value "X" to page 0 with if-sequence-number-lt set to 2 succeeds.

  5. A request to write value "Y" to page 0 with if-sequence-number-lt set to 2 succeeds.

  6. The original request is finally processed, but it fails because it specifies the condition that the sequence number must be less than 1 (that is, the if-sequence-num-lt header is set to 1). The error is SequenceNumberConditionNotMet (HTTP status code 412 – Precondition Failed).

  7. Reading page 0 returns the expected value of "Y".

See also

Authorize requests to Azure Storage
Status and error codes
Set time-outs for Blob service operations