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

Nidhi Jangir 21 Reputation points
2021-06-24T11:29:24.177+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:

  1. Enabling storage lifecycle management using dashboard (https://learn.microsoft.com/en-us/azure/storage/blobs/storage-lifecycle-management-concepts?tabs=template)
  2. Enabling soft delete a blob using dashboard again (https://learn.microsoft.com/en-us/azure/storage/blobs/soft-delete-blob-overview)
  3. Setting blob expiry using a PUT call (https://learn.microsoft.com/en-us/rest/api/storageservices/set-blob-expiry)

I was wondering if it's possible to do so using the azure client itself instead of us having to making changes to dashboards or using the REST PUT call. This will provide flexibility for us to set expiry time at runtime without having to go and make these static changes.

Awaiting your response.
Thanks

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,201 questions
{count} votes

Accepted answer
  1. deherman-MSFT 38,021 Reputation points Microsoft Employee Moderator
    2021-06-25T16:43:06.4+00:00

    @Nidhi Jangir
    Lifecycle management is available for the .NET SDK. Please review the sample code here and let us know if you have any questions.

    Hope this helps! Let us know if you have further questions.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. AlphaLion 0 Reputation points
    2023-08-08T07:59:10.63+00:00
    1. create retention rule:

    {"rules":[{"enabled":true,"name":"DeleteArtiTmp","type":"Lifecycle","definition":{"actions":{"baseBlob":{"delete":{"daysAfterCreationGreaterThan":1}}},"filters":{"prefixMatch":["somepath/"],"blobTypes":["blockBlob"],"blobIndexMatch":[{"name":"ttl","op":"=","value":"oneDay"}]}}},{"enabled":true,"name":"DeleteArtiLng","type":"Lifecycle","definition":{"actions":{"baseBlob":{"delete":{"daysAfterCreationGreaterThan":5}}},"filters":{"prefixMatch":["somepath/"],"blobTypes":["blockBlob"],"blobIndexMatch":[{"name":"ttl","op":"=","value":"fiveDays"}]}}}]}

    1. enable indexing on the azure blob storage container.
    2. add metadata KV to files during upload: ttl=oneDay or ttl=fiveDays
    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.