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

为君一笑 提交于 2019-12-01 17:08:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/33518637/how-to-retrieve-azure-blob-storage-file-attributes-such-as-create-data-and-audit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!