How to set expiry/TTL for file uploaded to Azure Blob Storage using Azure Client?

Tata, Aparna 0 Reputation points
2024-11-11T13:48:36.02+00:00

Hi Azure team,

I have looking to figure out ways one can use to set some expiry/Time to live for a file uploaded in the Azure Blob. So far, I have come across:

https://learn.microsoft.com/en-us/answers/questions/450426/how-to-set-expiry-ttl-for-file-uploaded-to-azure-b

But i am unable to find the answer in the link provided as marked

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,968 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Deepanshukatara-6769 11,545 Reputation points
    2024-11-11T14:00:19.6433333+00:00

    Hello Aparna, Welcome to MS Q&A

    To set the expiration or Time to Live (TTL) for a file uploaded to Azure Blob Storage, you can use the Cache-Control header. The TTL is determined by this header in the HTTP response from the origin server. Here are several methods to set the Cache-Control header

    1. Azure Storage Explorer:
      • Select the blob, right-click and choose Properties.
      • Find the CacheControl property, enter your desired value, and save.
    2. Azure CLI:
      • When uploading a blob, you can set the cache-control header using the -p switch. For example, to set the TTL to one hour (3600 seconds):
                azure storage blob upload -c <connectionstring> -p cacheControl="max-age=3600" .\<blob name> <container name> <blob name>
                
             
             
        
    3. Azure Storage Services REST API:
      • You can explicitly set the x-ms-blob-cache-control property using operations like Put Blob, Put Block List, or Set Blob Properties.

    If you do not set a TTL, Azure CDN applies a default TTL of seven days, unless caching rules are configured in the Azure portal.

    References:

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.