Python 从一个容器复制到另一个容器时保留blob的内容类型
我正在尝试从一个容器复制blob:Python 从一个容器复制到另一个容器时保留blob的内容类型,python,azure,Python,Azure,我正在尝试从一个容器复制blob: blob_url = blob_service.make_blob_url(source_container, source_blob, sas_token) blob_service.copy_blob(target_container, target_blob, blob_url) 这种情况正在发生,但是源blob的内容类型是application/pdf,而目标容器的内容类型设置为:application/vnd.openxmlformats offi
blob_url = blob_service.make_blob_url(source_container, source_blob, sas_token)
blob_service.copy_blob(target_container, target_blob, blob_url)
这种情况正在发生,但是源blob
的内容类型是application/pdf,而目标容器的内容类型设置为:application/vnd.openxmlformats officedocument.wordprocessingml.document
在Blob存储UI中,我可以单击此Blob的属性并更改内容类型,但是,如何在Azure Python SDK中做到这一点?您可以使用设置Blob\u属性
方法:
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存储blob==1.4.0
,当使用copy\u blob
方法时,内容类型也被复制为“application/pdf”,这不应该发生。复制blob操作保留源blob的属性。所以目标blob的内容类型应该和源blob的内容类型相同。我知道,这很奇怪。也许正如Ivan Young在回答中提到的,这是一个版本问题?我可以使用设置blob\u属性
解决方法。