Monday, 3 April 2017

S3.getSignedUrl to accept multiple content-type

I'm using the react-s3-uploader node package, which takes in a signingUrlfor obtaining a signedUrl for storing an object into S3.

Currently I've configured a lambda function (with an API Gateway endpoint) to generate this signedUrl. After some tinkering, I've got it to work, but noticed that I have to define in my lambda function the content-type, which looks like this:

var AWS = require('aws-sdk');
const S3 = new AWS.S3()
AWS.config.update({
  region: 'us-west-2'
})

exports.handler = function(event, context) {
  console.log('context, ', context)
  console.log('event, ', event)
  var params = {
    Bucket: 'video-bucket',
    Key: 'videoname.mp4',
    Expires: 120,
    ACL: 'public-read',
    ContentType:'video/mp4'
  };
  S3.getSignedUrl('putObject', params, function (err, url) {
    console.log('The URL is', url);
    context.done(null, {signedUrl: url})
  });  
}

The issue is that I want this signed url to be able to accept multiple types of video files, and I've tried setting ContentType to video/*, which doesn't work. Also, because this lambda endpoint isn't what actually takes the upload, I can't pass in the filetype to this function beforehand.



via Michael Du

No comments:

Post a Comment