Home > Back-end >  Azure BlobServiceClient Error InvalidResourceName
Azure BlobServiceClient Error InvalidResourceName

Time:02-19

Having problem uploading file to azure blob storage container, using azure.storage.blob for python 2.7. (I know i should use newer python, but it's a part of big ROS application, hence not just so to upgrade it all.)

from azure.storage.blob import BlobServiceClient
...
container_name = "operationinput"
self.back_up_root = "~/backup/sql/lp/"
self.back_up_root = os.path.expanduser(self.back_up_root)
file = 'test.sql'

try:
    client = BlobServiceClient.from_connection_string(conn_str=connection_string)
    blob = client.get_blob_client(container='container_name', blob='datafile')
except Exception as err:
    print(str(err))

with open(self.back_up_root   file, "rb") as data:
    blob.upload_blob(data)

I get the following error:

azure.core.exceptions.HttpResponseError: The specifed resource name contains invalid characters.
RequestId:3fcb6c26-101e-007e-596d-1c7d61000000
Time:2022-02-07T21:58:17.1308670Z
ErrorCode:InvalidResourceName

All post i have found refers to people using capital letters or so, but i have: operationinput datafile

All should be within specification.

Any ideas?

CodePudding user response:

We have tried with below sample code to upload files to Azure blob storage (Container ) using SAS token , and can able to achieve it successfully.

Code sample:-

from azure.storage.blob import BlobClient

upload_file_path="C:\\Users\\Desktop\\filename"
sas_url="https://xxx.blob.core.windows.nethttps://cloudsh3D?sastoken"

client = BlobClient.from_blob_url(sas_url)

with open(upload_file_path,'rb') as data:
    client.upload_blob(data)

print("**file uploaded**")

enter image description here

To generate SAS url and connection string we have selected as below:- enter image description here

enter image description here

For more information please refer this Microsoft Documentation: Allow or disallow public read access for a storage account

  • Related