Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon s3 AWS S3签名不匹配_Amazon S3_Aws Sdk - Fatal编程技术网

Amazon s3 AWS S3签名不匹配

Amazon s3 AWS S3签名不匹配,amazon-s3,aws-sdk,Amazon S3,Aws Sdk,我在s3.getSignedUrl上遇到了错误“签名不匹配,签名计算不匹配…”。我已经检查了证件和其他很多事情,但没有任何进展。我的访问密钥和密码保存在凭证文件中 我得到的网址是 upload.js文件: function getSignedRequest(file) { const xhr = new XMLHttpRequest(); xhr.open('GET', `/api/feed/sign-s3?file-name=${file.name}&file-type

我在s3.getSignedUrl上遇到了错误“签名不匹配,签名计算不匹配…”。我已经检查了证件和其他很多事情,但没有任何进展。我的访问密钥和密码保存在凭证文件中

我得到的网址是

upload.js文件:

function getSignedRequest(file) {
    const xhr = new XMLHttpRequest();
    xhr.open('GET', `/api/feed/sign-s3?file-name=${file.name}&file-type=${file.type}`);
    xhr.onreadystatechange = () => {
        if(xhr.readyState === 4){
            if(xhr.status === 200){
                const response = JSON.parse(xhr.responseText);
                uploadFile(file, response.signedRequest, response.url);
            } else {
                alert('Could not get signed URL');
            }
        }
    };
    xhr.send();
}

function uploadFile(file, signedRequest, url){
    const xhr = new XMLHttpRequest();
    xhr.open('PUT', signedRequest);
    xhr.onreadystatechange = () => {
        if(xhr.readyState === 4) {
            if(xhr.status === 200) {
                $('#preview').src = url;
                $('#avatar-url').value = url;
            } else {
                alert('Could not upload file');
            }
        }
    };
    xhr.send(file);
}
路由文件:

router.get('/sign-s3', (req, res) => {
    const s3 = new aws.S3();
    const fileName = req.query['file-name'];
    const fileType = req.query['file-type'];
    const s3Params = {
        Bucket: S3_BUCKET,
        Key: fileName,
        Expires: 600,
        // ACL: 'public-read',
        // ContentType: fileType
    };

    s3.getSignedUrl('putObject', s3Params, (err, data) => {
        if(err) {
            console.log(err);
            return res.end();
        }
        console.log(data);
        const returnData = {
            signedRequest: data,
            url: `https://${S3_BUCKET}.s3.amazonaws.com/${fileName}`
        };
        res.write(JSON.stringify(returnData));
        res.end();
    });
});