Download file from AZURE BLOB CONTAINER using SAS URI in PYTHON

时间秒杀一切 提交于 2019-12-11 15:59:05

问题


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

//This is java code for same.

CloudBlobContainer Con = new CloudBlobContainer("Some SAS URI");

CloudBlockBlob blob1 = Con.getBlockBlobReference(fileName);

blob1.downloadToFile(filePath+fileName+userName);

回答1:


There is no equivalent method in python, you can take a look at the Container class of python

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")


来源:https://stackoverflow.com/questions/55794030/download-file-from-azure-blob-container-using-sas-uri-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!