0

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
  • What kind of SAS URI do you have? Is it for the blob container or blob? Please edit your question and include the SAS URI (you can obfuscate the account name and sig portion of the SAS URI). Commented Apr 22, 2019 at 13:45

2 Answers 2

3

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")
Sign up to request clarification or add additional context in comments.

2 Comments

Yes it works fine thanks I didn't knew that BlockBlobService method has sas_token parameter also.
@Amitvishnoi, could you please help mark it as an answer. here is the link of how to mark if you don't know, thank you.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.