本文介绍了获取SignatureDoesNotMatch:使用multers3 node.js将图像上传到DigitalOcean Spaces时出现null错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Error: code:'SignatureDoesNotMatch'
extendedRequestId:undefined
message:null
name:'SignatureDoesNotMatch'
region:null
// Load dependencies
const aws = require('aws-sdk');
const express = require('express');
const multer = require('multer');
const multerS3 = require('multer-s3');
const app = express();
// Set S3 endpoint to DigitalOcean Spaces
const spacesEndpoint = new aws.Endpoint('fra1.digitaloceanspaces.com');
const s3 = new aws.S3({
endpoint: spacesEndpoint,
accessKeyId: '*************',
secretAccessKey: '**********************************'
});
// Change bucket property to your Space name
const upload = multer({
storage: multerS3({
s3: s3,
bucket: 'bucket',
acl: 'public-read',
key: function (request, file, cb) {
console.log(file);
cb(null, file.originalname);
}
})
}).array('upload', 1);
// Views in public directory
app.use(express.static('public'));
// Main, error and success views
app.get('/', function (request, response) {
response.sendFile(__dirname + '/public/index.html');
});
app.get("/success", function (request, response) {
response.sendFile(__dirname + '/public/success.html');
});
app.get("/error", function (request, response) {
response.sendFile(__dirname + '/public/error.html');
});
app.post('/upload', function (request, response, next) {
upload(request, response, function (error) {
if (error) {
console.log(error);
return response.redirect("/error");
}
console.log('File uploaded successfully.');
response.redirect("/success");
});
});
app.listen(3001, function () {
console.log('Server listening on port 3001.');
});
尝试此博客(用于数字海洋空间示例)
Trying this blog for digital ocean spaces example
推荐答案
我遇到了同样的问题,唯一有用的就是重置密钥
I had the same problem, the only thing that helped was to reset the keys
这篇关于获取SignatureDoesNotMatch:使用multers3 node.js将图像上传到DigitalOcean Spaces时出现null错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!