Python:如何将 Azure Blob 从一个容器移动或复制到另一个容器 [英] Python: How to move or copy Azure Blob from one container to another
问题描述
我在项目中使用 Microsoft Azure SDK for Python.我想将 Blob 从一个容器移动或复制到另一个容器.例如
I am using Microsoft Azure SDK for Python in project. I want to move or copy Blob from one container to another. for exmaple
https://demostorage.blob.core.windows.net/image-container/pretty.jpg
我想把这个 blob 移动到
I want to move this blob to
https://demostorage.blob.core.windows.net/demo-container/
我在python SDK中找到了以下方法但无法理解.
I have found following method in python SDK but unable to understand it.
def copy_blob(self, container_name, blob_name,...):
我该怎么做?谢谢
推荐答案
我已经这样做了.
from azure.storage.blob import BlobService
def copy_azure_files(self):
blob_service = BlobService(account_name='account_name', account_key='account_key')
blob_name = 'pretty.jpg'
copy_from_container = 'image-container'
copy_to_container = 'demo-container'
blob_url = blob_service.make_blob_url(copy_from_container, blob_name)
# blob_url:https://demostorage.blob.core.windows.net/image-container/pretty.jpg
blob_service.copy_blob(copy_to_container, blob_name, blob_url)
#for move the file use this line
blob_service.delete_blob(copy_from_container, blob_name)
我还没有找到任何 Blob Move 方法.所以我使用了copy方法,然后执行Blob函数.
I have not found any Blob Move method yet. So I have used the copy method and then execute Blob function.
这是我的解决方案.如果您有更好的方法来处理这一切,请与我分享.
This is my solution. If you have better way to handle all this please share with me.
注意:我没有使用任何自定义方法,所有这些方法都包含在 SDK 中.
Note: I have not used any custom method all these methods are included in SDK.
这篇关于Python:如何将 Azure Blob 从一个容器移动或复制到另一个容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!