我已经按照应有的方式进行了所有设置,但是当我尝试上传时,出现此错误:
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);
});
}
};