"Missing config credentials" on first attempt
I'm having this error while trying to upload an object to S3 on the FIRST attempt only. The second one goes through...
this is my method:
this.s3PutObject = function (file, bucketPath, onResponse, onHttpUploadProgress) { var bucket = new AWS.S3({ params: { Bucket: bucketPath } }); AWS.config.update({ accessKeyId: AAKID, secretAccessKey: SAK }); AWS.config.region = 'us-west-2';
if (file) {
// Perform File Size Check First
var fileSize = Math.round(parseInt(file.size));
if (fileSize > 2097152000) { //2GB file limit
return onResponse('FILE_TOO_BIG');
}
// Prepend Unique String To Prevent Overwrites
var uniqueFileName = uniqueString() + '-' + file.name;
var params = { Key: uniqueFileName, ContentType: file.type, Body: file, ServerSideEncryption: 'AES256' };
console.log('params: %s', JSON.stringify(params));
bucket.putObject(params, function (err, data) {
return onResponse(err, data);
})
.on('httpUploadProgress', onHttpUploadProgress);
}
else {
onResponse('NO_FILE_SELECTED');
}
};
Can you try updating credentials before constructing the service object?
AWS.config.update({ accessKeyId: AAKID, secretAccessKey: SAK });
AWS.config.region = 'us-west-2';
var bucket = new AWS.S3({ params: { Bucket: bucketPath } });
This is because credentials are sourced from AWS.config when constructing a service object.
Let me know if the error persists after making this change.
That worked @AdityaManohar . Thanks!
Sure! I'm closing this as resolved.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.