简体   繁体   English

从Azure存储中获取Blob时出错(HTTP请求)[VueJs]

[英]Error while get a blob from Azure storage (HTTP request) [VueJs]

I am trying to check if the blob with the path that I have exists in the Azure storage container or not. 我正在尝试检查Azure存储容器中是否存在具有路径的Blob。

this is my request: 这是我的要求:

let current_user_img = "https://XXXX.blob.core.windows.net/avatar/" + Img_name + ".png";

const instance = axios.create({
   timeout: 3000,
   headers: {
       "Access-Control-Allow-Origin" : "*",
       "Access-Control-Allow-Methods": "GET,POST,PUT",
       "Access-Control-Allow-Headers": "x-ms-*,content-*",
       "content-type": "application/json",
   }
});
instance .get( current_user_img )
.then(function(response) {
    console.log("User have an avatar.");
    console.log(response);
})
.catch(function(error) {
    console.log("User doesn't have an avatar.");
    console.log(error);
});

And the CORS for my storage is as follows: 我的存储的CORS如下:

ALLOWED ORIGINS: '*'
ALLOWED METHODS: 'put,get,post'
ALLOWED HEADERS: '*'
EXPOSED HEADERS: '*'
MAX AGE: 0

when I try to run the code, I faced this error: 当我尝试运行代码时,遇到了以下错误:

Failed to load https://XXXX.blob.core.windows.net/avatar/XXXXXXXX.png: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

How can I solve it? 我该如何解决?

Try adding the withCredentials: true prop to your request: 尝试将withCredentials: true添加到您的请求中:

const instance = axios.create({
   withCredentials: true,  
   timeout: 3000,     
   headers: {
       "Access-Control-Allow-Origin" : "*",
       "Access-Control-Allow-Methods": "GET,POST,PUT",
       "Access-Control-Allow-Headers": "x-ms-*,content-*",
       "content-type": "application/json",
   }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 向 Azure Blob 存储 [REST API] [Azure Blob 存储] 发出 GET 请求时授权失败 - Authorization Failed while making GET Request to Azure Blob Storage [REST API][Azure Blob Storage] 如何读取 Azure 函数 HTTP 请求的参数并使用 blob 存储中的文件进行响应? - How to read parameters of Azure function HTTP request and respond with a file from blob storage? VueJS http获取请求 - VueJS http get request 如何从 azure blob 存储中获取图像作为文件? - How to get the image from azure blob storage as file? JSON API的VueJs2 HTTP获取请求 - VueJs2 HTTP Get Request from JSON API 进行 REST API 调用以获取 AZURE 存储 BLOB 中的容器详细信息时身份验证失败 - Authentication Failed while making REST API call to GET container details in AZURE STORAGE BLOB 如何使用浏览器方法将文件上传到 azure blob 存储时取得进展 - How to get progress while uploading file to azure blob storage using Browser method 从 Angular 向 Azure 存储 Blob 添加文件 - Adding File to Azure Storage Blob from Angular 列出 Azure 中的 Blob 存储和读取流 Node.js - List blob from Azure Blob Storage and Readstream in Node.js AJAX CORS PUT到Azure Blob存储返回405错误 - AJAX CORS PUT to Azure Blob Storage returning 405 Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM