如何在 Azure 中正确设置元数据



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

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

但它没有用。我应该再做什么?!

您需要

调用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);
        }
    }

最新更新