Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从一个容器复制到另一个容器时保留blob的内容类型_Python_Azure - Fatal编程技术网

Python 从一个容器复制到另一个容器时保留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:

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 sdk
azure存储blob==1.4.0
,当使用
copy\u blob
方法时,内容类型也被复制为“application/pdf”

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