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.
3,100 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deepanshu katara 14,160 Reputation points MVP
    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

  2. KarishmaTiwari-MSFT 20,572 Reputation points Microsoft Employee
    2024-12-04T00:33:12.3733333+00:00

    @Tata, Aparna In addition to above, you can use Azure Blob Storage Lifecycle Management or SAS tokens.

    Lifecycle management policies allow you to automate data retention and expiration by defining rules that automatically delete blobs or move them to cooler storage tiers after a specific time period. You can configure these policies through the Azure portal or programmatically using Azure SDKs.

    SAS tokens provide a way to grant temporary access to a blob by specifying an expiration time. This is useful if you need a limited-time link to a file and want the file to be inaccessible after a certain time.

    For automating the deletion or movement of blobs after a certain period, Azure Blob Storage Lifecycle Management is the best option whereas for controlled temporary access to a blob, a Shared Access Signature (SAS) with an expiration date is ideal.

    Let me know if you have any questions.

    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.