How to retrieve Creation Date of Azure.Storage.Blobs Item

2.1k Views Asked by At

I am trying to delete a blob if it has been created(cannot be modified) 7+ days earlier so I need to know when the file has been created. When I saw that not only blobItem.Properties.LastModified but also blobItem.Properties.CreatedOn was nullable I started googeling. I read that even CreatedOn is not really set when I upload a blob. ( I am using DataLakeFileClient.UploadAsync for that)

Still Azure Storage Explorer shows DateModified in Blop Properties but it's not accessible:

var blobServiceClient = new BlobServiceClient(StorageConnectionString);
            var blobContainerClient = blobServiceClient.GetBlobContainerClient(containerName);
            var blobItems = blobContainerClient.GetBlobsAsync();
            await foreach (var blobItem in blobItems)
            {
                if (blobItem.Properties.CreatedOn.HasValue)
                {
                   
                }
                else
                {  // always end up here
        }

So I tried to set MetaData in Storage Explorer but I cannot read them either:

        _logger.LogInformation(string.Join(';',blobItem.Metadata.Keys));

Strangely they also disappear in Storage Explorer once they have been saved.

Any ideas how to workaround these issues?

1

There are 1 best solutions below

0
On

We cannot repro this issue for Azure Data Lake storage gen2. You'd better use the latest version of Storage Explorer, or it's just a temp issue.

It is always recommended to use lifecycle management to delete blobs after a specified period.

And for fileClient.ScheduleDeletionAsync(new DataLakeFileScheduleDeletionOptions(TimeSpan.FromMinutes(1), DataLakeFileExpirationOrigin.Now));, its pricing is the same as lifecycle management, you only need to pay the cost by writing operation, the delete operation is free(this code is actually used Set Blob Expiry in the backend, which will set the file's ExpiresOn property). Here is the screenshot of the ADLS Gen2 pricing:

enter image description here

By using this code, you can control the time for deletion which is better than lifecycle management. But you should manage your code / environment by yourself.