Reputation: 1
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);
Upvotes: 0
Views: 5249
Reputation:
If you are using newer version that does not have BlockBlobService
, you can use BlobClient
:
from azure.storage.blob import BlobClient
blob_client = BlobClient.from_blob_url(sas_url)
with open(file=blob_client.blob_name, mode="wb") as blob_file:
download_stream = blob_client.download_blob()
blob_file.write(download_stream.readall())
Upvotes: 0
Reputation: 29940
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")
Upvotes: 3