python - 如何为 azure blob 创建/设置新元数据并使用 Python API 获取元数据?

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

我有这样的元数据:

    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

我需要设置获取这些元数据的函数吗?

最佳答案

Python对“blob”中的 azure “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(....) 行代码。

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

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

关于python - 如何为 azure blob 创建/设置新元数据并使用 Python API 获取元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25451378/

相关文章:

python - 如何从 efetch(Biopython、Entrez)中提取摘要?

python - python fastparquet 模块可以读取压缩的 Parquet 文件吗?

python - 如何在python中将时区添加到天真的日期时间实例中

azure - MarkLogic - XDMP-HOSTOFFLINE : Host is offline or not responding

azure - AKS 群集托管标识中的 Nginx 服务无权读取 publicIPAddresses

azure - 在一次调用中检索存储库及其标签版本的列表

azure - 如何在非管理员帐户下启动Azure存储模拟器

angular - 在 Azure blob 存储上托管时如何使 Angular 路由正常工作

Azure 资源管理器 - Microsoft.Storage/storageAccounts 与 microsoft.classic storage/storageAccounts

python - Pyramid_beaker : session. type = cookie 不安全?