Set Blob Expiry

The Set Blob Expiry operation sets an expiration date on an existing blob. This operation is allowed only on hierarchical namespace-enabled accounts. Applies to service version 2020-02-10 and later.

Request

The Set Blob Expiry request may be constructed 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=expiry HTTP/1.1

Emulated Storage Service URI

When you're making a request against the emulated storage service, specify the emulator hostname and Blob Storage 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=expiry 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 Storage operations.

Request headers

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

Request header Description
Authorization Required. Specifies the authentication scheme, account name, and signature. See Authentication for the Azure Storage services for more information.
Date or x-ms-date Required. Specifies the Coordinated Universal Time (UTC) for the request. For more information, see Authentication for the Azure Storage services.
x-ms-version Required for all authenticated requests. Specifies the version of the operation to use for this request. For more information, see Versioning for the Azure Storage services.
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-expiry-option Required. To specify the expiration date option for the request, see ExpiryOption.
x-ms-expiry-time Optional. The time when the file is set to expire. The format for expiration date varies according to x-ms-expiry-option. For more information, see ExpiryOption.
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.

ExpiryOption

You can send the following values as an x-ms-expiry-option header. This header isn't case-sensitive.

Expiration option Description
RelativeToCreation Sets the expiration date relative to the time of file creation. x-ms-expiry-time must be specified as the number of milliseconds to elapse from the time of creation.
RelativeToNow Sets the expiration date relative to the current time. x-ms-expiry-time must be specified as the number of milliseconds to elapse from the present time.
Absolute x-ms-expiry-time must be specified as an absolute time, in RFC 1123 format.
NeverExpire Sets the file to never expire or removes the current expiration date. x-ms-expiry-time must not be specified.

Request body

The request body for this request is empty.

Sample request

Request Syntax:  
PUT https://myaccount.blob.core.windows.net/mycontainer/myblob?comp=expiry HTTP/1.1  
  
Request Headers:  
x-ms-version: 2020-02-10  
x-ms-date: Sun, 25 Sep 2020 14:37:35 GMT
x-ms-expiry-option: RelativeTonow
x-ms-expiry-time: 30000  
Authorization: SharedKey myaccount:J4ma1VuFnlJ7yfk/Gu1GxzbfdJloYmBPWlfhZ/xn7GI=    

Response

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

Status code

A successful operation returns status code 200 (OK).

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
ETag Contains a value that represents the version of the file. The value is enclosed in quotation marks.
Last-Modified Returns the date and time when the directory was last modified. The date format follows RFC 1123. For more information, see Represent date/time values in headers. Any operation that modifies the directory or its properties updates the last modified time. Operations on files don't affect the last modified time of the directory.
x-ms-request-id Uniquely identifies the request that was made and can be used to troubleshoot the request. For more information, see Troubleshoot API operations.
x-ms-version Indicates 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.

Sample response

Response Status:  
HTTP/1.1 200 OK  
  
Response Headers:  
Date: Sun, 25 Sep 2011 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 Set Blob Expiry 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 Set Blob Expiry 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 semantics for setting an expiration date on a blob are as follows:

  • Set Expiry can be set only on a file and not a directory.
  • Set Expiry with an expiryTime in the past isn't allowed.
  • ExpiryTime can't be specified with an expiryOption value of Never.

Note

An expired file can't be restored by using the blob soft delete feature. Even if you've enabled soft delete for the account, an expired file doesn't become a soft deleted blob when it expires. Only files that are deleted can become soft deleted files.

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 Set Blob Expiry requests based on the storage account type:

Operation Storage account type Billing category
Set Blob Expiry Premium block blob
Standard general-purpose v2
Other operations
Set Blob Expiry Standard general-purpose v1 Write operations

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

See also