Joined April 2014
·

Joe VanWanzeele

South Bend, IN
·
·

Good catch! Here's the solution in node.js in case it will help anyone:

signs3: function(req, res){
var AWS
ACCESSKEY = <access key from config>;
var AWS
SECRETKEY = <secret key from config>;
var S3
BUCKET = <bucket name>;

var object_name = uuid.v4(); //I'm using uuids as my object_names
var mime_type = req.query.s3_object_type;

var now = new Date();
var expires = Math.ceil((now.getTime() + 60000)/1000); // 60 seconds from now
var amz_headers = "x-amz-acl:public-read";

var put_request = "PUT\n\n"+mime_type+"\n"+expires+"\n"+amz_headers+"\n/"+S3_BUCKET+"/"+object_name;

var signature = crypto.createHmac('sha1', AWS_SECRET_KEY).update(put_request).digest('base64');

signature = signature.replace('+','%2B')
                                 .replace('/','%2F')
                                 .replace('=','%3D');
signature = encodeURIComponent(signature.trim());

var url = 'https://'+S3_BUCKET+'.s3.amazonaws.com/'+object_name;

var credentials = {
    signed_request: url+"?AWSAccessKeyId="+AWS_ACCESS_KEY+"&Expires="+expires+"&Signature="+signature,
    url: url
};
res.write(JSON.stringify(credentials));
res.end();

},

Achievements
19 Karma
0 Total ProTip Views
Interests & Skills