问题
I'm attempting to upload a file to an S3 bucket of mine from a web browser using AWS' JavaScript SDK. My code looks like this:
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
AccountId: 'dfhgdh',
IdentityPoolId: 'fdagsd',
RoleArn: 'fdafds'
});
var bucket = new AWS.S3({params: {Bucket: 'test-bucket'}});
var pdfUpload = document.getElementById('pdf-uploads').files[0];
var params = {Key: pdfUpload.name, ContentType: pdfUpload.type, Body: pdfUpload};
bucket.putObject(params, function (error, data) {
if (error) {
console.log(error);
} else {
console.log(data);
}
});
However, whenever it reaches the putObject command, I keep getting an error back from AWS:
"Error: Missing credentials in config {message: "Missing credentials in config", code: "CredentialsError"..."
I'm sure I'm missing something simple and stupid here, but I can't figure out what for the life of me. (I get a different error when I try to just hardcode a bogus secret key in or something, so I'm pretty sure it has something to do with the way I'm trying to set up cognito credentials.)