我试图检查具有我存在的路径的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.
我该如何解决?
尝试将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",
}
});