在PYTHON中使用SAS URI从AZURE BLOB CONTAINER下载文件 [英] Download file from AZURE BLOB CONTAINER using SAS URI in PYTHON
本文介绍了在PYTHON中使用SAS URI从AZURE BLOB CONTAINER下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有Azure容器,用于存放一些文件. 我需要使用python代码访问它们 我在JAVA中做了同样的事情,但是我无法在Python中复制它
I have Azure container where i keep some files. I need to access them using python code I did same thing in JAVA but i am unable to replicate it in Python
//这是相同的Java代码.
//This is java code for same.
CloudBlobContainer Con = new CloudBlobContainer("Some SAS URI");
CloudBlockBlob blob1 = Con.getBlockBlobReference(fileName);
blob1.downloadToFile(filePath+fileName+userName);
推荐答案
There is no equivalent method in python, you can take a look at the Container class of python
您应该始终将BlockBlobService
与sas令牌(如果您有sas uri,则可以从中获取sas令牌)或帐户密钥一起使用,例如,如果您使用sas令牌,则如下所示:
You should always use BlockBlobService
with sas token(if you have a sas uri, you can get sas token from it) or account key, like below if you use sas token:
from azure.storage.blob import BlockBlobService
blobservice = BlockBlobService("storage_account",sas_token="?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-04-24T10:01:58Z&st=2019-04-23T02:01:58Z&spr=https&sig=xxxxxxxxx")
blobservice.get_blob_to_path("container_name","blob_name","local_file_path")
这篇关于在PYTHON中使用SAS URI从AZURE BLOB CONTAINER下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文