-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Hey there!
I want to implement a remote method for uploading images to Amazon S3.
According to the article http://docs.strongloop.com/display/public/LB/Storage+service I defined amazon's credentials in /server/datasources.json
.
Then in my model's code I am trying to implement a remote method:
Hike.uploadImage = uploadImage;
Hike.remoteMethod(
'uploadImage',
{
description: 'Upload hike\'s image',
http: {verb: 'post'},
returns: {arg: 'data', type: 'Object', root: true}
}
);
function uploadImage(next) {
var s3 = Hike.app.datasources.s3.createModel('HikeFile');
s3.getContainers(function (err, data) {
err && next (err, {});
next(null, data);
});
}
At this stage this method only returns S3 buckets info & it works fine.
But if I replace s3.getContainers()
call by s3.getContainer('myBucket`, fn), then this method return Error:
{
"error": {
"name": "InvalidRequest",
"status": 400,
"message": "The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.",
"code": "InvalidRequest",
"time": "2015-01-27T07:59:28.751Z",
"statusCode": 400,
"retryable": false,
"retryDelay": 30,
"stack": "InvalidRequest: The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.\n at Request.extractError ..."
}
}
I've made some research & found out that this error is caused by my bucket region requirement to use AWS Signature Version 4 for authentication.
If I use aws-sdk for Node.js to make requests to Amazon S3 API then I need to specify signatureVersion
parameter: var s3 = new AWS.S3({signatureVersion: 'v4', region: 'eu-central-1'});
.
How can I circumvent the problem in LoopBack?