如何使用Python将Azure中的文件从一个存储帐户复制到另一个存储帐户? [英] How to copy a file in Azure from a one storage account to another using Python?

查看:132
本文介绍了如何使用Python将Azure中的文件从一个存储帐户复制到另一个存储帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一段代码,将文件从一个容器复制到同一存储帐户中的另一个容器.

I have written a piece of code to copy a file from one container to another within the same storage account.

  block_blob_service = BlockBlobService(
  account_name='', account_key='')

  blob_name = file_name
  copy_from_container = source
  copy_to_container = destination
  blob_url = block_blob_service.make_blob_url(copy_from_container, blob_name)
  # blob_url:https://demostorage.blob.core.windows.net/image-container/pretty.jpg
  block_blob_service.copy_blob(copy_to_container, blob_name, blob_url)

但是现在我想跨不同的存储帐户复制文件. 我该怎么办?

But now I want to copy files across different storage accounts. How can I do that?

推荐答案

跨存储帐户复制Blob的基本方法大致相同.您需要执行以下操作:

Basically approach for copying a blob across storage accounts would remain more or less the same. You would need to do something like the following:

  source_block_blob_service = BlockBlobService(
  source_account_name= '', source_account_key= '')

  target_block_blob_service = BlockBlobService(
  target_account_name= '', target_account_key= '')

  blob_name = file_name
  copy_from_container = source
  copy_to_container = destination
  blob_url = source_block_blob_service.make_blob_url(copy_from_container, blob_name)
  # blob_url:https://demostorage.blob.core.windows.net/image-container/pretty.jpg
  target_block_blob_service.copy_blob(copy_to_container, blob_name, blob_url)

请注意,在跨存储帐户复制Blob时,应可公开访问源Blob URL.您可以通过创建对源blob至少具有读取权限的共享访问签名(SAS)URL(推荐方法),或将源blob容器的ACL(copy_from_container)的ACL设置为Blob(不推荐).

Please note that when copying blob across storage account, the source blob URL should be publicly accessible. You can do so by either creating a Shared Access Signature (SAS) URL with at least read permission on the source blob (recommended approach) or make the ACL of source blob container (copy_from_container) as Blob (not recommended).

这篇关于如何使用Python将Azure中的文件从一个存储帐户复制到另一个存储帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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