从本地路径(从我的计算机)上传文件不是问题。但是,我没有找到如何从特定的URL上传。
如果可能-需要使用Python解决方案。仅提供有关本地文件https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python
的文档如何对远程URL执行此操作?
答案 0 :(得分:4)
您可以利用async copy blob
功能通过可公开访问的URL创建Blob。请参见下面的示例代码:
from azure.storage.blob import BlockBlobService, PublicAccess
from azure.storage.blob.models import Blob
def run_sample():
block_blob_service = BlockBlobService(account_name='your_name', account_key='your_key')
container_name ='t1s'
block_blob_service.copy_blob(container_name,'remoteURL.pdf','https://media.readthedocs.org/pdf/azure-storage/v0.20.3/azure-storage.pdf')
# Main method.
if __name__ == '__main__':
run_sample()
答案 1 :(得分:2)
您可以first download the file as stream
,然后调用方法create_blob_from_stream
。
以下是演示代码:
from azure.storage.blob import BlockBlobService, PublicAccess
from azure.storage.blob.models import Blob
import requests
def run_sample():
block_blob_service = BlockBlobService(account_name='your_name', account_key='your_key')
container_name ='t1s'
response = requests.get('https://media.readthedocs.org/pdf/azure-storage/v0.20.3/azure-storage.pdf',stream=True)
block_blob_service.create_blob_from_stream(container_name,'remoteURL.pdf',response.raw)
# Main method.
if __name__ == '__main__':
run_sample()
测试结果如下: http://jsfiddle.net/y04nse5x/1/
答案 2 :(得分:0)
好吧,还有另外一个信息,因为我看到这个脚本时很困惑。
您可以在portal.azure.com上找到的account_name和account_key信息:
资源组->选择资源组,其中是Blob存储->选择存储帐户->单击左侧面板上的访问键。
account_name =存储帐户名(例如:mybackupstorage)
account_key =密钥(例如:ihwIKU @ Hsniq87dbki *&qlos8ejuwa3ox7w4rykwij7ryx83deozd)
from azure.storage.blob import BlockBlobService, PublicAccess
from azure.storage.blob.models import Blob
import requests
def run_sample():
block_blob_service = BlockBlobService(account_name='', account_key='')
container_name ='container-name'
response = requests.get('https://media.readthedocs.org/pdf/azure-storage/v0.20.3/azure-storage.pdf',stream=True)
block_blob_service.create_blob_from_stream(container_name,'remoteURL.pdf',response.raw)
# Main method.
if __name__ == '__main__':
run_sample()