gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 01:12:56 24 4
gpt4 key购买 nike

我正在尝试检查 Azure 存储容器中是否存在具有我所拥有的路径的 blob。

这是我的要求:

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 属性添加到您的请求中:

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

关于javascript - 从 Azure 存储获取 blob 时出错(HTTP 请求)[VueJs],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52141224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com