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

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

问题描述

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

共享代码和参考的响应-

  filepath ="/home/meera/Downloads/download.pdf"account_name ="account_name";container_name ="container_name";名称="doc.pdf"sas_token ="sas_token";使用open(filepath,'rb')as f:file_content = f.read()标头= {"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响应= request.put(URL,标头=标头,数据= file_content) 

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

解决方案

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

 #[START upload_a_blob]#上传内容以阻止Blob使用open(SOURCE_FILE,"rb")作为数据:blob_client.upload_blob(数据,blob_type ="BlockBlob")#[END upload_a_blob]#[START download_a_blob]使用open(DEST_FILE,"wb")作为my_blob:download_stream = blob_client.download_blob()my_blob.write(download_stream.readall())#[END download_a_blob] 

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

使用rest api需要一些标头,请在此处检查: https://docs.microsoft.com/zh-cn/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天全站免登陆