【问题标题】:how to set Metadata correctly in azure如何在 azure 中正确设置元数据
【发布时间】:2017-10-25 10:03:53
【问题描述】:

我尝试通过这种方式保存元数据:

     public void SaveMetaData(string fileName, string container, string key, string value)
    {
        try
        {
            var blob = GetBlobReference(fileName, container);
            blob.FetchAttributes();
            blob.Metadata.Add(key,value);
        }
        catch (Exception e)
        {
            _logger.Error(e,
                "An Exception occured  with blobname = {0} and blobcontainer = {1}", fileName,
                container);
        }
    }

但它不起作用。我应该怎么做呢?!

【问题讨论】:

    标签: c# asp.net-mvc azure


    【解决方案1】:

    您需要调用SetMetadata() 来实际保存元数据。你的代码应该是这样的:

        public void SaveMetaData(string fileName, string container, string key, string value)
        {
            try
            {
                var blob = GetBlobReference(fileName, container);
                blob.FetchAttributes();
                blob.Metadata.Add(key, value);
                blob.SetMetadata();//This line of code will save the metadata.
            }
            catch (Exception e)
            {
                _logger.Error(e,
                    "An Exception occured  with blobname = {0} and blobcontainer = {1}", fileName,
                    container);
            }
        }
    

    【讨论】:

    • 再次嗨,如果我只希望 blob 中的一个项目具有特定值(true)而 blob 中的所有其他项目具有(false)值,我该怎么做?!提前致谢
    • 欢迎来到 Stack Overflow Rezo!请针对您的这个问题发布一个新问题,并附上您可以分享的所有详细信息。谢谢。
    • 我只是添加了关于我的问题的所有详细信息的新问题stackoverflow.com/questions/46935088/add-edit-metadata-in-azure
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    • 2013-07-28
    • 2018-12-27
    相关资源
    最近更新 更多