如何将文件上传到Azure Blob存储? [英] How to upload files to azure blob storage?

查看:183
本文介绍了如何将文件上传到Azure Blob存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天需要从本地系统上载文件到azure blob容器.我将azcopy与sas一起使用.但是我遇到的是容器的SAS在每次刷新时都在不断变化.因此,有没有更好的方法可以使用python或azcopy上传文件.还是有任何方法无需登录即可从天蓝色获取SAS令牌并将该SAS令牌传递给azcopy命令?到目前为止,我从azcopy使用此命令

I need to upload files to azure blob container every day from local system. I use azcopy with sas for doing it. But what i encountered is that SAS for container keep changing on every refresh. So is there any better way i can upload files using python or azcopy. Or is there any way to get the SAS toke from the azure without login and pass that SAS token to azcopy command? as of now i use this command from azcopy

.\azcopy "Sourcefilepath" "Destblobpath?SAS_Token" --recurcive=true

每天我都应该登录到azure获取SAS令牌并传递上述命令.我尝试使用.\ azcopy登录,但登录成功,但是无法发送文件

Each day i should login to azure get the SAS token and pass for the above command. i tried .\azcopy login and i get login successful, but i cant send files with

.\azcopy "Sourcepath" "Destpath"

不知道我在哪里做错了.

Don't know where i'm doing wrong.

推荐答案

如果您使用的是python,我建议您使用azure python sdk进行上传.您可以在此示例中看到更多内容...

If you're using python, I would suggest using the azure python sdk to do your uploading. You can see more from this example here...

https://github.com/Azure-Samples/storage-blobs-python-quickstart/blob/master/example.py

它可以像这样快(从快速入门文档:

It can be as quick as this (from the quick start docs : https://docs.microsoft.com/en-us/python/api/overview/azure/storage?view=azure-python) to interface with your azure blob storage account. Just put in some logic to loop through a directory recursively and upload each file.

首先请确保pip安装所需的软件包,然后从门户网站获取您的帐户名(blob存储名)和访问密钥...将它们插入即可,一切准备就绪.

First make sure to pip install the required packages, and then grab your account name (blob storage name) and your access key from the portal...plug them in and you're good to go.

pip install azure-storage-blob azure-mgmt-storage

然后在此处编写一些python代码...

Then write some python code here...

from azure.storage.blob import BlockBlobService, PublicAccess

blob_service = BlockBlobService('[your account name]','[your access key]')

blob_service.create_container(
    'mycontainername',
    public_access=PublicAccess.Blob
)

blob_service.create_blob_from_bytes(
    'mycontainername',
    'myblobname',
    b'hello from my python file'
)

print(blob_service.make_blob_url('mycontainername', 'myblobname'))

这应该使您很快地朝正确的方向前进.

This should get you going in the right direction pretty quickly.

这篇关于如何将文件上传到Azure Blob存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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