首页 > 解决方案 > Azure Blob 存储错误:指定的资源不存在

问题描述

我正在尝试通过 REST API 在 Azure Blob 存储中上传文件。容器的访问级别设置为 - 容器(对容器和 bolb 的匿名读取访问)。

共享代码和响应以供参考-

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)

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

标签: pythonapiazure-blob-storage

解决方案


当然,您的解决方案很棒,但我们总是在这样的代码中使用 python-sdk:

            # [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]

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

使用 rest api 需要一些标头,请在此处查看:https ://docs.microsoft.com/en-us/rest/api/storageservices/put-blob


推荐阅读