简体   繁体   中英

How to retrieve azure blob storage file attributes such as create data and audit trail in c#

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 (eg 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM