Reputation: 33
I have a couple of questions regarding uploading to SAS using Python. I have a SAS provided by our client, in the form of:
https://<company_name>.blob.core.windows.net/<container_name>?sp<long_string>
I tried following this code: Uploading csv files to azure container using SAS URI in python?
from azure.storage.blob import BlobClient
upload_file_path="d:\\a11.csv"
sas_url="https://xxx.blob.core.windows.net/test5/a11.csv?sastoken"
client = BlobClient.from_blob_url(sas_url)
with open(upload_file_path,'rb') as data:
client.upload_blob(data)
print("**file uploaded**")
and I get the following error:
azure.core.exceptions.ResourceExistsError: Public access is not permitted on this storage account.
RequestId:946bd6ea-e01e-0040-3932-ee6a4e000000
Time:2021-12-11T01:58:51.0010075Z
ErrorCode:PublicAccessNotPermitted
The Azure SDK mentions using an account name which I do not have so that's a no go (I can upload file using the Azure Storage Explorer however that is slow for what I need, but I know the SAS is working). Am I using the wrong code for uploading? Also, it is not clear how to tell the code where to upload the file to in the blob container? E.g. if I wanted to upload a file image.jpg
to 2021-12-11/dataset_1/
, where would I put that in the code?
Upvotes: 2
Views: 5455
Reputation: 4893
I tried to upload file using SAS URL which i have generated from container , and unable to upload the file. Instead of using SAS URL of Container use your storage account SAS URL which is worked fine for me with the same code which you have given .
cmd
Here are the output screenshots:For more information please refer this MS DOC & &Github sample
Upvotes: 1