I am trying to create a solution that allows my customers to store their files in azure blob storage.
When I do this:
foreach(var blob in list.OfType<CloudBlockBlob>())
{
blob.FetchAttributes();
var file = new FileViewModel()
{
Name = blob.Name,
Modified= blob.Properties.LastModified,
Size = blob.Properties.Length,
Created= xxx
}
}
Looks like there is no Create date property, just lastModified. Does it mean I have to put created date into Metadata Property myself?
I am quite new to Azure blob storage, and needs to produce an audit report (e.g. when the file was created, modified and accessed), do I need to put all the information into either my database or file's Metadata? If the customer overrides existing file which is stored in blob, will existing metadata be lost?
To restore a soft-deleted blob in the Azure portal when blob versioning is not enabled, first display the blob's properties, then select the Undelete button on the Overview tab. Restoring a blob also restores any snapshots that were deleted during the soft-delete retention period.
To retrieve metadata, call the GetProperties or GetPropertiesAsync method on your blob or container to populate the Metadata collection, then read the values, as shown in the example below. The GetProperties methods retrieve blob properties and metadata in a single call.
View a blob container's contentsOpen Storage Explorer. In the left pane, expand the storage account containing the blob container you wish to view. Expand the storage account's Blob Containers. Right-click the blob container you wish to view, and - from the context menu - select Open Blob Container Editor.
You're correct in your observation. There's no property which would tell you when the blob was created. It only has a property which tells you when a blob was last modified.
If you want to store created date as metadata, that would work however please keep in mind metadata will be overwritten when the blob is updated unless you preserve the metadata manually by fetching it before blob is updated and saving it along with blob update operation.
A better approach would be to make use of Azure Table Storage along with blob storage. In this approach, when a blob is created you write an entry into Azure Table Storage. Also when a blob is updated, you make another entry into Azure Table Storage. This was you will be able to build an audit trail.
If you're interested in keeping a history of blobs (for example user uploaded a text file and then uploaded another text file and you want to keep track of both text files contents), then what you could do is take a snapshot of the blob before it is being updated. What it will do is create a read-only copy of the existing blob. When a snapshot is created, the process returns you a date/time value that you can store along with your updated entry in table storage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With