Python:如何将Azure Blob从一个容器移动或复制到另一个容器 [英] Python: How to move or copy Azure Blob from one container to another

查看:170
本文介绍了Python:如何将Azure Blob从一个容器移动或复制到另一个容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用用于Python的Microsoft Azure SDK .我想将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,...):

我该怎么做?谢谢

推荐答案

我已经按照这种方式完成了.

I have done in this way.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆