"SignatureDoesNotMatch" 当使用 axios 使用签名 link 将图像放入 Digital Ocean 空间时
"SignatureDoesNotMatch" when using axios to put image in Digital Ocean spaces using signed link
我正在尝试通过在 node.js 中创建带符号的 url,在本机反应中使用 axios 将图像插入数字海洋空间。 url 正确生成,但是当我尝试使用 url 插入图像时,出现 "Signature Does Not Match" 错误。这是我的 axios 代码:
const fd = new FormData();
fd.append("image", {
uri: this.state.image.path,
type: "image/jpeg",
name: data.key
});
axios(data.url, {
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data'
},
method: 'PUT',
data: fd
}).then((data) => {
console.log(data);
});
这是我的 node.js 代码:
const spacesEndpoint = new AWS.Endpoint("xyz");
const s3 = new AWS.S3({
endpoint: spacesEndpoint,
accessKeyId: "xyz",
secretAccessKey: "yzx"
});
app.post("/getPreSignedURL", function(req, res) {
const params = {
Bucket: "trialspace",
Key: Math.random() + ".jpg",
ContentType: 'multipart/form-data'
};
s3.getSignedUrl("putObject", params, function(err, url) {
console.log("Your generated pre-signed URL is", url);
var contentType = params.ContentType;
var key = params.Key;
res.send({ url, contentType, key });
});
});
然而,当我如图所示使用 xmlHttpRequest 而不是 axios 时,一切正常。所以我认为空间权限或节点服务器没有任何问题。
编辑:
这是来自 axios 的请求和响应日志。出于某种原因,axios 正在从 header.
中删除我的内容类型
我通过删除转换请求中的授权 headers 解决了这个问题,如下所示:
axios({
url: "mySignedUrl",
data: {
uri: this.state.image.path,
type: "image/jpeg",
name: "0.3789520076534978.jpg"
},
method: "put",
headers: {
"Content-Type": "image/jpeg",
"x-amz-acl": "public-read"
},
transformRequest: [
(data, headers) => {
delete headers.common.Authorization;
return data;
}
]
})
正在讨论这个问题here
我正在尝试通过在 node.js 中创建带符号的 url,在本机反应中使用 axios 将图像插入数字海洋空间。 url 正确生成,但是当我尝试使用 url 插入图像时,出现 "Signature Does Not Match" 错误。这是我的 axios 代码:
const fd = new FormData();
fd.append("image", {
uri: this.state.image.path,
type: "image/jpeg",
name: data.key
});
axios(data.url, {
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data'
},
method: 'PUT',
data: fd
}).then((data) => {
console.log(data);
});
这是我的 node.js 代码:
const spacesEndpoint = new AWS.Endpoint("xyz");
const s3 = new AWS.S3({
endpoint: spacesEndpoint,
accessKeyId: "xyz",
secretAccessKey: "yzx"
});
app.post("/getPreSignedURL", function(req, res) {
const params = {
Bucket: "trialspace",
Key: Math.random() + ".jpg",
ContentType: 'multipart/form-data'
};
s3.getSignedUrl("putObject", params, function(err, url) {
console.log("Your generated pre-signed URL is", url);
var contentType = params.ContentType;
var key = params.Key;
res.send({ url, contentType, key });
});
});
然而,当我如图所示使用 xmlHttpRequest 而不是 axios 时,一切正常。所以我认为空间权限或节点服务器没有任何问题。
编辑: 这是来自 axios 的请求和响应日志。出于某种原因,axios 正在从 header.
中删除我的内容类型我通过删除转换请求中的授权 headers 解决了这个问题,如下所示:
axios({
url: "mySignedUrl",
data: {
uri: this.state.image.path,
type: "image/jpeg",
name: "0.3789520076534978.jpg"
},
method: "put",
headers: {
"Content-Type": "image/jpeg",
"x-amz-acl": "public-read"
},
transformRequest: [
(data, headers) => {
delete headers.common.Authorization;
return data;
}
]
})
正在讨论这个问题here