Put Blob

Updated: February 26, 2015

The Put Blob operation creates a new block blob or page blob, or updates the content of an existing block blob.

Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with Put Blob; the content of the existing blob is overwritten with the content of the new blob. To perform a partial update of the content of a block blob, use the Put Block List operation.

Note that calling Put Blob to create a page blob only initializes the blob. To add content to a page blob, call the Put Page operation.

For a page blob, the value of this header must be set to zero, as Put Blob is used only to initialize the page blob. The page blob's size is specified in the x-ms-blob-content-length header. All content must be written to a page blob by calling Put Page.

Content-Type

Optional. The MIME content type of the blob. The default type is application/octet-stream.

Content-Encoding

Optional. Specifies which content encodings have been applied to the blob. This value is returned to the client when the Get Blob operation is performed on the blob resource. 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. An MD5 hash of the blob content. 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. If the two hashes do not match, the operation will fail with error code 400 (Bad Request).

When omitted in version 2012-02-12 and later, the Blob service generates an MD5 hash.

Optional. The Blob service stores this value but does not use or modify it.

x-ms-blob-content-type

Optional. Set the blob’s content type.

x-ms-blob-content-encoding

Optional. Set the blob’s content encoding.

x-ms-blob-content-language

Optional. Set the blob's content language.

x-ms-blob-content-md5

Optional. Set the blob’s MD5 hash.

x-ms-blob-cache-control

Optional. Sets the blob's cache control.

x-ms-blob-type:<BlockBlob | PageBlob>

Required. Specifies the type of blob to create: block blob or page blob.

x-ms-meta-name:value

Optional. Name-value pairs associated with the blob as metadata.

Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers.

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-blob-content-disposition

Optional. Sets the blob’s Content-Disposition header. Available for versions 2013-08-15 and later.

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. 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.

The following table describes request headers applicable only for operations on page blobs.

Request header

Description

x-ms-blob-content-length: bytes

Required for page blobs. This header specifies the maximum size for the page blob, up to 1 TB. The page blob size must be aligned to a 512-byte boundary.

If this header is specified for a block blob, the Blob service returns status code 400 (Bad Request).

x-ms-blob-sequence-number: <num>

Optional. Set for page blobs only. The sequence number is a user-controlled value that you can use to track requests. The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.

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.

Response header

Description

ETag

The ETag contains a value that the client can use to perform conditional 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.

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

This header is returned for a block blob so the client can check the integrity of message content. The Content-MD5 value returned is computed by the Blob service. 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-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.

Access-Control-Allow-Origin

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

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

Returned if the request includes an Origin header and CORS is enabled with a matching rule that does not allow all origins. This header will be set to true.

When you create a blob, you must specify whether it is a block blob or a page blob. Once a blob has been created, the type of the blob cannot be changed unless it is deleted and re-created.

To create a new page blob, first initialize the blob by calling Put Blob and specify its maximum size, up to 1 TB. When creating a page blob, do not include content in the request body. Once the blob has been created, call Put Page to add content to the blob or to modify it.

The maximum upload size for a block blob is 64 MB. If your blob is larger than 64 MB, you must upload it as a set of blocks. For more information, see the Put Block and Put Block List operations. It's not necessary to call Put Blob if you upload the blob as a set of blocks.

If you attempt to upload a block blob that is larger than 64 MB, or a page blob larger than 1 TB, the service returns status code 413 (Request Entity Too Large). The Blob service also returns additional information about the error in the response, including the maximum blob size permitted in bytes.

If you call Put Blob to overwrite an existing blob with the same name, any snapshots associated with the original blob are retained. To remove associated snapshots, call Delete Blob first, then Put Blob to re-create the blob.

A blob has custom properties (set via headers) that you can use to store values associated with standard HTTP headers. These values can subsequently be read by calling Get Blob Properties, or modified by calling Set Blob Properties. The custom property headers and corresponding standard HTTP header are listed in the following table:

HTTP header

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

The semantics for setting persisting these property values with the blob as follows:

If the client specifies a custom property header, as indicated by the x-ms-blob prefix, this value is stored with the blob.

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. 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.

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.

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

A Put Blob operation is permitted 10 minutes per MB to complete. If the operation is taking longer than 10 minutes per MB on average, the operation will timeout.