如何在C#中检索Azure Blob存储文件属性,例如创建数据和审核跟踪 [英] How to retrieve azure blob storage file attributes such as create data and audit trail in c#

查看:97
本文介绍了如何在C#中检索Azure Blob存储文件属性,例如创建数据和审核跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一种解决方案,以允许我的客户将其文件存储在azure blob存储中.

I am trying to create a solution that allows my customers to store their files in azure blob storage.

当我这样做时:

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
            }
        }

好像没有创建日期属性,只有lastModified.这是否意味着我必须自己将创建日期放入Metadata Property中?

Looks like there is no Create date property, just lastModified. Does it mean I have to put created date into Metadata Property myself?

我对Azure Blob存储还很陌生,需要生成审核报告(例如,在创建,修改和访问文件时),我是否需要将所有信息放入数据库或文件的元数据中?如果客户覆盖存储在Blob中的现​​有文件,现有的元数据会丢失吗?

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?

推荐答案

您的观察是正确的.没有属性可以告诉您Blob的创建时间.它只有一个属性,可以告诉您上次修改Blob的时间.

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.

如果您想将创建的日期存储为元数据,则可以使用,但是请记住,在更新Blob时元数据将被覆盖,除非您手动保存元数据,方法是在更新Blob之前先获取元数据并将其与Blob更新一起保存操作.

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.

更好的方法是将Azure表存储与blob存储一起使用.通过这种方法,在创建Blob时,您将一个条目写入Azure Table Storage.同样,在更新Blob时,您还要在Azure Table Storage中进行另一个输入.这样您就可以建立审核跟踪.

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.

如果您有兴趣保存Blob的历史记录(例如,用户上传了一个文本文件,然后又上传了另一个文本文件,并且您想跟踪两个文本文件的内容),那么您可以做一个快照对其进行更新之前的Blob的值.它将要做的是创建现有Blob的只读副本.创建快照后,该过程将为您返回日期/时间值,您可以将其与更新的条目一起存储在表存储中.

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.

这篇关于如何在C#中检索Azure Blob存储文件属性,例如创建数据和审核跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆