AWS s3上传错误:InvalidIdentityPoolConfigurationException:配置中缺少凭证

时间:2020-10-27 18:15:55

标签: amazon-web-services amazon-s3

我正在尝试使用本教程https://medium.com/@shresthshruti09/uploading-files-in-aws-s3-bucket-through-javascript-sdk-with-progress-bar-d2a4b3ee77b5

将文件上传到s3存储桶

我已经按照应有的方式进行了所有设置,但是当我尝试上传时,出现此错误: error: InvalidIdentityPoolConfigurationException: Missing credentials in config

代码如下:

//Bucket Configurations
var bucketName = "name-of-bucket";
var bucketRegion = "us-east-2";
var IdentityPoolId = "[Identity Pool Id]";
AWS.config.update({
    region: bucketRegion,
    credentials: new AWS.CognitoIdentityCredentials({
        IdentityPoolId: IdentityPoolId
    })
});

var s3 = new AWS.S3({
    apiVersion: '2006-03-01',
    params: {Bucket: bucketName}
});
function s3upload() {
    var files = document.getElementById('screenshot').files;
    if (files) {
        var file = files[0];
        var fileName = file.name;
        var filePath = 'name-of-bucket/' + fileName;
        var fileUrl = 'https://' + bucketRegion + '.amazonaws.com/name-of-bucket/feedback-screenshots/' +  filePath;
        s3.upload({
            Key: filePath,
            Body: file,
            ACL: 'public-read'
        }, function(err, data) {
            if(err) {
                console.log('error:', err);
            } else {
                alert('Successfully Uploaded!');
            }
        }).on('httpUploadProgress', function (progress) {
            var uploaded = parseInt((progress.loaded * 100) / progress.total);
            $("progress").attr('value', uploaded);
        });
    }
};

0 个答案:

没有答案