Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update LastModified on an Azure Blob

I'm porting code to work with Azure's Storage SDK in C#.

Traditionally, I'd call this to update modified the last write/modified time of a file:

File.SetLastWriteTimeUtc(fileName, lastWriteTimeUtc);

To update a blob's last modified time, I'm trying to do something like this but can't because LastModified is not accessible:

CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
blob.Properties.LastModified = lastWriteTimeUtc;
blob.SetProperties();

Compiler error:

Property or indexer 'Microsoft.WindowsAzure.Storage.Blob.BlobProperties.LastModified' cannot be assigned to -- it is read only

How can I update the LastModified property? It won't always be updated to the current time, so I can't just reupload/touch the file.

like image 389
marchica Avatar asked Sep 19 '25 00:09

marchica


1 Answers

Azure allows you to add METADATA to the containers and blobs. LastModified is an internal property and there is no point to let external parties update it - it should reflect its meaning.

In your case, it seems that you want to keep old values after migrating content, and content might not allow to add property inside. Say, it is an image.

In this case use Metadata to add and read additional properties. Article about Metadata on MSDN

like image 129
Ivan Kirkorau Avatar answered Sep 20 '25 15:09

Ivan Kirkorau