【问题标题】:Preserve content type of a blob while copying from one container to another从一个容器复制到另一个容器时保留 blob 的内容类型
【发布时间】:2019-06-06 17:15:52
【问题描述】:

我正在尝试从一个容器中复制一个 blob:

blob_url = blob_service.make_blob_url(source_container, source_blob, sas_token)
blob_service.copy_blob(target_container, target_blob, blob_url)

这是正常的,但是source_blob的内容类型是application/pdf,target_container的内容类型被设置为:application/vnd.openxmlformats-officedocument.wordprocessingml.document

在 Blob 存储 UI 中,我可以单击此 Blob 的属性并更改内容类型,但是,如何在 Azure Python SDK 中执行此操作?

【问题讨论】:

  • 这不应该发生。复制 blob 操作会保留源 blob 的属性。所以目标 blob 的内容类型应该与源 blob 的内容类型相同。
  • 我知道,这很奇怪。也许正如 Ivan Young 在他们的回答中提到的那样,这是一个版本问题?我可以使用set_blob_properties 解决方法。

标签: python azure


【解决方案1】:

您可以使用set_blob_properties 方法:

from azure.storage.blob import BlockBlobService, ContentSettings

accountName="xxx"
accountKey="xxxx"

services = BlockBlobService(account_name=accountName,account_key=accountKey)

#set the content_type to whatever you need
settings = ContentSettings(content_type='application/pdf')

services.set_blob_properties(container_name,blob_name,content_settings=settings)

顺便说一下,我用的是python sdkazure-storage-blob==1.4.0,当使用copy_blob方法时,content-type也复制为“application/pdf”

【讨论】:

    猜你喜欢
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 2020-03-29
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多