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

问题描述 投票:0回答:1

我试图检查具有我存在的路径的blob是否存在于Azure存储容器中。

这是我的要求:

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);
});

我存储的CORS如下:

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

当我尝试运行代码时,我遇到了这个错误:

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.

我该如何解决?

javascript azure vue.js vuejs2 azure-storage
1个回答
1
投票

尝试将withCredentials: true prop添加到您的请求中:

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",
   }
});
© www.soinside.com 2019 - 2024. All rights reserved.