代码之家  ›  专栏  ›  技术社区  ›  blue piranha

在Azure blob存储中设置和检索blob的元数据

  •  0
  • blue piranha  · 技术社区  · 6 年前

    link 提到在容器级别存储和检索元数据。我只是想知道是否可以设置和检索关于存储在该容器内目录中的blob的元数据?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Gaurav Mantri    6 年前

    我只是想知道是否可以设置和检索元数据 关于存储在该容器内目录中的blob?

    是的,你当然可以这样做。请参见下面的示例代码:

            const string ConnectionString = "DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
    
            //Create the service client object for credentialed access to the Blob service.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    
            // Retrieve a reference to a container.
            CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
    
            CloudBlockBlob blob = container.GetBlockBlobReference("images/logo.png");
            blob.FetchAttributes();//Gets the properties & metadata for the blob.
            blob.Metadata.Add("Key", "Value");
            blob.SetMetadata();//Saves the metadata.