【问题标题】:How do I create/set a new metadata to an azure blob and get the metadata by using Python API?如何使用 Python API 创建/设置新元数据到 azure blob 并获取元数据?
【发布时间】:2014-10-16 13:33:56
【问题描述】:

我有这样的元数据:

    Container: mycontainer
        Object: myblob
  Content Type: application/octet-stream Charset=UTF-8
Content Length: 26
          ETag: "0x8D18C1E18C0CF2C"

我想添加更多元数据,例如:

     Meta Century: Nineteenth
       Meta Author: Mustafa

添加后应该是:

     Container: azure
        Object: myblob
  Content Type: application/octet-stream Charset=UTF-8
Content Length: 26
          ETag: "0x8D18C1E18C0CF2C"
  Meta Century: Nineteenth
   Meta Author: Mustafa

我需要setget那些元数据的函数吗?

【问题讨论】:

    标签: python azure azure-storage azure-blob-storage


    【解决方案1】:

    这个 Python 编码设置获取一个天蓝色“blob”的元数据在一个“容器”:

    from azure.storage import BlobService
    blob_service = BlobService(account_name='myaccount', account_key='mykey')
    
    # set metadata to "myblob" of container "mycontainer"
    blob_service.set_blob_metadata(container_name="mycontainer",
                                   blob_name="myblob",
                                   x_ms_meta_name_values={"Meta Century":"Nineteenth","Meta Author":"Mustafa"})
    
    #get metadata of "myblob" of container "mycontainer"
    metadata = blob_service.get_blob_metadata(container_name="mycontainer",blob_name="myblob")
    print metadata
    

    以上代码“仅”返回用户使用设置的元数据

    blob_service.set_blob_metadata(....) 代码行。

    如果您需要内容类型或其他元数据(标题),您应该使用:

    blob_service.get_blob("mycontainer", "myblob").__dict__["properties"]
    

    【讨论】:

    • 看起来现在有一个 get_blob_properties() 方法可以避免在字典的幕后达到峰值,例如blob_service.get_blob_properties("mycontainer", "myblob"),将返回包括用户集元数据在内的所有属性。
    猜你喜欢
    • 2019-12-16
    • 2019-07-10
    • 2019-08-12
    • 2020-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多