我有一个MEAN堆栈应用程序,我正在尝试允许用户下载使用Amazon S3存储的文件。我正在为用户生成预签名网址,但是当我在Chrome中转到该网址时,我收到以下错误消息
The request signature we calculated does not match the signature you provided. Check your key and signing method.
当我从Postman查询节点应用程序时,它会生成一个带有问题的假定的预先签名的URL,但显然它不起作用。这是我的相关代码:
var express=require('express');
var S3 = require('aws-sdk/clients/s3');
var router = express.Router();
router.get('/api/downloadURL', (req,res,next) => {
const s3 = new S3({
apiVersion: '2006-03-01',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
signatureVersion: 'v4',
region: 'us-east-2' // region of my bucket and what it says is expected
});
var s3params = {'Bucket': process.env.S3_BUCKET_NAME, 'Key': 'folder1/file.pdf'}
s3.getSignedUrl('getObject', s3params, function(err, url) {
if (err) res.json(err);
res.json(url);
});
});
当邮递员查询时,我会得到以下格式的网址