I created a bucket on aws and IAM user, then set up access permissions for the user.
Now I'm stuck because I don't know how to use aws-sdk to upload an image. I can't find any example (all the examples I found use key and secret key, not IAM).
Please give me the working example or fix my code that is apparently not working:
var awsFileName = entityType.awsFolder + entityId + '/' + fileName; //get filename like /folder1/folder2/filename
aws.config.update({
region: 'ca-central-1',
accessKeyId: awsKey // like 'ADXZJMPSVCU3KOAXGJJL'
});
var s3 = new aws.S3();
var s3Bucket = new aws.S3( { params: {Bucket: 'testbucket'} } );
var awsFileData = {Key: awsFileName, Body: data};
s3Bucket.putObject(data, function(err, data){
if (!err)
{
callbackOk(fileName, awsFileName);
console.log('succesfully uploaded the image!');
} else {
console.log('Error uploading data: ', data);
callbackFail();
}
});
What I have now is error "Missing required key 'Key' in params" and 45,000 (!!!) errors with the same text "Error: Unexpected key 'N' found in params(…)" where N is number of errors.