Jaa


Put Block From URL

The Put Block From URL operation creates a new block to be committed as part of a blob where the contents are read from a URL. This API is available as of version 2018-03-28.

Request

You can construct the Put Block From URL 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=block&blockid=id 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=block&blockid=id HTTP/1.1

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

URI parameters

Parameter Description
blockid Required. A valid Base64 string value that identifies the block. Prior to encoding, the string must be less than or equal to 64 bytes in size.

For a specified blob, the length of the specified value for the blockid parameter must be the same size for each block.

Note: The Base64 string must be URL-encoded.
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. For Put Block From URL, the version has to be 2018-03-28 or later.
Content-Length Required. Specifies the number of bytes being transmitted in the request body. The value of this header must be set to 0. When the length isn't 0, the operation fails with status code 400 (Bad Request).
x-ms-copy-source:name Required. Specifies the URL of the source blob. The value can be a URL of up to 2 kibibytes (KiB) in length that specifies a blob. The value should be URL-encoded, as it would appear in a request URI. The source blob must be either public or authorized via a shared access signature. If the source blob is public, no authorization is required to perform the operation. Here are some examples of source object URLs:

- https://myaccount.blob.core.windows.net/mycontainer/myblob
- https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=<DateTime>
- https://myaccount.blob.core.windows.net/mycontainer/myblob?versionid=<DateTime>
x-ms-copy-source-authorization: <scheme> <signature> Optional. Specifies the authorization scheme and signature for the copy source. For more information, see Authorize requests to Azure Storage.

Note: Only a bearer scheme is supported for Microsoft Entra.

Note: If your source object is publicly accessible or your source object is in a storage account and you are using a SAS token that is being passed in x-ms-copy-source:name, this header is not needed.

This header is supported in versions 2020-10-02 and later.
x-ms-source-range Optional. Uploads only the bytes of the blob in the source URL in the specified range. If this header isn't specified, the entire source blob contents are uploaded as a single block. For more information, see Specify the range header for Blob service operations.
x-ms-source-content-md5 Optional. An MD5 hash of the block content from the URI. This hash is used to verify the integrity of the block during transport of the data from the URI. When this header is specified, the storage service compares the hash of the content that has arrived from the copy-source with this header value.

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-source-content-crc64 Optional. A CRC64 hash of the block content from the URI. This hash is used to verify the integrity of the block during transport of the data from the URI. When this header is specified, the storage service compares the hash of the content that has arrived from the copy-source 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 x-ms-source-content-md5 and x-ms-source-content-crc64 headers are present, the request fails with a 400 (Bad Request).

This header is supported in versions 2019-02-02 and later.
x-ms-encryption-scope Optional. Indicates the encryption scope to use to encrypt the source contents. This header is supported in versions 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-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.

Request headers (customer-provided encryption keys)

As of 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

None.

Sample request

Request Syntax:  
PUT https://myaccount.blob.core.windows.net/mycontainer/myblob?comp=block&blockid=AAAAAA%3D%3D HTTP/1.1  
  
Request Headers:  
x-ms-version: 2018-03-28  
x-ms-date: Sat, 31 Mar 2018 14:37:35 GMT    
Authorization: SharedKey myaccount:J4ma1VuFnlJ7yfk/Gu1GxzbfdJloYmBPWlfhZ/xn7GI=  
Content-Length: 0
x-ms-copy-source: https://myaccount.blob.core.windows.net/mycontainer/myblob
x-ms-source-range: bytes=0-499

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 header Description
Content-MD5 Returned so that the client can check for message content integrity. The value of this header is computed by Blob Storage. It isn't necessarily the same as the value that's specified in the request headers. For versions 2019-02-02 and later, this header is returned only when the request has this header.
x-ms-content-crc64 For versions 2019-02-02 and later. Returned so that the client can check for message content integrity. The value of this header is computed by Blob Storage. It isn't necessarily the same as value that's specified in the request headers.

Returned when x-ms-source-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 Blob Storage version that was used to execute the request.
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 block 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. 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.

Sample response

Response Status:  
HTTP/1.1 201 Created  
  
Response Headers:  
Transfer-Encoding: chunked  
x-ms-content-crc64: 77uWZTolTHU  
Date: Sat, 31 Mar 2018 23:47:09 GMT  
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 Block From URL 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 Block From URL 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

Put Block From URL uploads a block for future inclusion in a block blob. A block blob can include a maximum of 50,000 blocks. Each block can be a different size. The maximum size for a block that's uploaded with Put Block From URL is 100 mebibytes (MiB). To upload larger blocks (up to 4,000 MiB), see Put Block.

In version 2020-10-02 and later, Microsoft Entra authorization is supported for the source of the copy operation.

A blob can have a maximum of 100,000 uncommitted blocks at any time. If this maximum is exceeded, the service returns status code 409 (RequestEntityTooLargeBlockCountExceedsLimit).

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

Service version Maximum block size (via Put Block From URL) Maximum blob size (via Put Block List) Maximum blob size via single write operation (via Put Blob From URL)
Version 2020-04-08 and later 4,000 MiB Approximately 190.7 tebibytes (TiB) (4,000 MiB × 50,000 blocks) 5,000 MiB
Versions earlier than 2020-04-08 100 MiB Approximately 4.75 TiB (100 MiB × 50,000 blocks) 256 MiB

After you've uploaded a set of blocks, you can create or update the blob on the server from this set by calling the Put Block List operation. Each block in the set is identified by a block ID that's unique within that blob. Block IDs are scoped to a particular blob, so different blobs can have blocks with same IDs.

If you call Put Block From URL on a blob that doesn't yet exist, a new block blob is created with a content length of 0. This blob is enumerated by the List Blobs operation if the include=uncommittedblobs option is specified. The block or blocks that you uploaded are not committed until you call Put Block List on the new blob. A blob created this way is maintained on the server for a week. If you haven't added more blocks or committed blocks to the blob within that time period, the blob is garbage collected.

A block that has been successfully uploaded with the Put Block From URL operation doesn't become part of a blob until it's committed with Put Block List. Before Put Block List is called to commit the new or updated blob, any calls to Get Blob return the blob contents without the inclusion of the uncommitted block.

If you upload a block that has the same block ID as another block that hasn't yet been committed, the last uploaded block with that ID is committed on the next successful Put Block List operation.

After Put Block List is called, all uncommitted blocks specified in the block list are committed as part of the new blob. Any uncommitted blocks that weren't specified in the block list for the blob is garbage collected and removed from Blob Storage. Any uncommitted blocks are also garbage collected if there are no successful calls to Put Block From URL or Put Block List on the same blob within a week following the last successful Put Block From URL operation. If Put Blob is called on the blob, any uncommitted blocks are garbage collected.

If the blob has an active lease, the client must specify a valid lease ID on the request to write a block to the blob. 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).

For a specified blob, all block IDs must be the same length. If a block is uploaded with a block ID of a different length from that of the block IDs for any existing uncommitted blocks, the service returns error response code 400 (Bad Request).

Calling Put Block From URL doesn't update the last modified time of an existing blob.

Calling Put Block From URL on a page blob returns an error.

Calling Put Block From URL on an 'archive' blob returns an error, and calling it on a hot or cool blob doesn't change the blob tier.

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 From URL requests based on the storage account type:

Operation Storage account type Billing category
Put Block From URL (destination account1) Premium block blob
Standard general-purpose v2
Standard general-purpose v1
Write operations
Put Block From URL (source account2) Premium block blob
Standard general-purpose v2
Standard general-purpose v1
Read operations

1The destination account is charged for one transaction to initiate the write.
2The source account incurs one transaction for each read request to the source object.

In addition, if the source and destination accounts reside in different regions (for example, US North and US South), the bandwidth that's used to transfer the request is charged to the source storage account as egress. Egress between accounts within the same region is free.

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

See also