2

I want to upload a couple of files to a container. I have tried the approaches mentioned here but it did not work.

Here's what I have:

SAS URL: https://xxxx.blob.core.windows.net?sp=acw&st=2022-05-31T17:54:22Z&se=2022-06-05T10:59:59Z&sv=2020-08-04&sr=c&sig=H0g%2BY%2FOnNIaYNVTsX%2FP42buWaowxIlxQDJ0xqH0gvqQ%3D

Container Name: XYZ

I want to upload the files to the container root, without any subfolders.

Edit: My code so far:

sas = 'https://xxxx.blob.core.windows.net?sp=acw&st=2022-05-31T17:54:22Z&se=2022-06-05T10:59:59Z&sv=2020-08-04&sr=c&sig=H0g%2BY%2FOnNIaYNVTsX%2FP42buWaowxIlxQDJ0xqH0gvqQ%3D'

container = 'container_name'
sasUrlParts = urlparse(sas)
accountEndpoint = sasUrlParts.scheme + '://' + sasUrlParts.netloc
sasToken = sasUrlParts.query

blobSasUrl = accountEndpoint + '/' + container + '?' + sasToken

blobClient = BlobClient.from_blob_url(blobSasUrl)

with open('/file_to_be_uploaded.csv', 'rb') as f:
    blobClient.upload_blob(f)

which produces the following error in the line blobClient = BlobClient.from_blob_url(blobSasUrl):

ValueError: Invalid URL. Provide a blob_url with a valid blob and container name
3
  • Please edit your question and include the code you’ve written so far and the issues you’re running into with that. Commented Jun 4, 2022 at 11:40
  • @GauravMantri Please check the edit. Commented Jun 4, 2022 at 11:54
  • Did you check the official docs? Commented Jun 4, 2022 at 12:00

1 Answer 1

7

I believe the reason you're getting the error is because your blobSasUrl does not include the name of the blob.

Please try by changing the following line of code:

blobSasUrl = accountEndpoint + '/' + container + '?' + sasToken

to

blobName = 'file_to_be_uploaded.csv'
blobSasUrl = accountEndpoint + '/' + container + '/' + blobName + '?' + sasToken

And you should not get the error you are getting.

Sign up to request clarification or add additional context in comments.

2 Comments

It ran successfully. Thanks! Is there a way to check if it had been uploaded correctly? I don't have read access to this container.
If you do not get an error, that would mean the blob uploaded successfully.

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.