I am curious to see if there is a way to automatically delete a blob file in the future in Microsoft azure by setting a future date or time? When the set time elapse, the blob file is automatically deleted. I am using c# ASP.NET.
Automatically delete Blob files in Azure based on a future date
3.1k Views Asked by user2447830 At
3
There are 3 best solutions below
0
On
There is no mechanism that can do this solely using blob storage.
Of course you can write a service that can query every blob and delete if exceeded TTL which you could store in the MetaData. You would be incurring costs for every read and delete.
0
On
1) There is no way to automatically delete a blob file in the future in Microsoft azure by setting a future date or time our of the box.
2) To acheive your goal, you shoud create a small app, this app could be:
- Azure worker role;
- Just desktop application;
- Something else (for example asp.net application, or even application written on Go).
App logic is pretty simple:
- Check blobs every
N
seconds and remove those that meet to reqirements (TTL is over). - You can use blob attributes or writing into the blob (or another
mechanism) to store
born time (BT)
. - You can write into the blob or make it a constant in your programm (or use another mechanism) to store
TTL
. - When you will check the blob, you should do:
(Current Time - BT) > TTL
and if it is 'true' you can delete blob
A blob is never going to delete itself. That would contradict the consistency and reliability of Azure if objects started deleting themselves.
The simplest thing to do that I can think of would be to set up a WebJob to monitor your storage account and remove blobs that are a specified number of days old. Or if you store metadata about a blob in your app database you could have the WebJob look into your database and delete any blob where the deletedate is today.
WebJobs can, if you're site isn't under any real pressure, be deployed to an existing WebApp process at no additional cost. If you expect either your WebApp or WebJob to be particularly busy I would consider separating them so they don't compete for resources.
There's a great blog post here that tells you all you need to know to get started with WebJobs.
It's worth noting that a WebJob can run continuously, on demand, on a defined schedule and in response to message queues or a file being dropped in blob storage.