Azure blob storage Error: The specified resource does not exist

Viewed 4024

I'm trying to upload file in Azure blob storage through REST API. Acess level for container is set to - Container(anonymous read access to container and bolb).

Sharing code and response for the reference-

filepath = "/home/meera/Downloads/download.pdf"
account_name = "account_name"
container_name = "container_name"
name = "doc.pdf"
sas_token = "sas_token"

with open(filepath, 'rb') as f:
    file_content = f.read() 
headers = { "Content-Type": "application/pdf; charset=UTF-8", "x-ms-blob-type": "BlockBlob" }
url = "https://"+ account_name+".blob.core.windows.net/"+container_name+"/"+name+sas_token
response = requests.put(url, headers=headers, data=file_content)

Error: <Response [404]> <Code>ResourceNotFound</Code><Message>The specified resource does not exist.

1 Answers

Of course your solution is great, but we always use python-sdk in code like this:

            # [START upload_a_blob]
            # Upload content to block blob
            with open(SOURCE_FILE, "rb") as data:
                blob_client.upload_blob(data, blob_type="BlockBlob")
            # [END upload_a_blob]

            # [START download_a_blob]
            with open(DEST_FILE, "wb") as my_blob:
                download_stream = blob_client.download_blob()
                my_blob.write(download_stream.readall())
            # [END download_a_blob]

Reference: https://docs.microsoft.com/en-us/azure/storage/common/storage-samples-python?toc=/azure/storage/blobs/toc.json

Using rest api requires some headers, check here: https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob

Related