Azure blob 存储错误:指定的资源不存在 [英] Azure blob storage Error: The specified resource does not exist

查看:66
本文介绍了Azure blob 存储错误:指定的资源不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

共享代码和响应供参考-

filepath = "/home/meera/Downloads/download.pdf";account_name = "account_name";container_name = "container_name";名称 =doc.pdf";sas_token = "sas_token";with open(filepath, 'rb') as f:file_content = f.read()headers = {内容类型":应用程序/pdf;charset=UTF-8",x-ms-blob-type":BlockBlob"}url = "https://"+ account_name+".blob.core.windows.net/"+container_name+"/"+name+sas_tokenresponse = requests.put(url, headers=headers, data=file_content)

错误:<代码><响应[404]><Code>ResourceNotFound</Code><Message>指定的资源不存在.

解决方案

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

 # [开始上传_a_blob]# 上传内容以阻止blob使用 open(SOURCE_FILE, "rb") 作为数据:blob_client.upload_blob(数据,blob_type=BlockBlob")# [END upload_a_blob]# [开始下载_a_blob]使用 open(DEST_FILE, "wb") 作为 my_blob:download_stream = blob_client.download_blob()my_blob.write(download_stream.readall())# [结束下载_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

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.

解决方案

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

这篇关于Azure blob 存储错误:指定的资源不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆