5

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.

Arafat Nalkhande
  • 11,078
  • 9
  • 39
  • 63
Michael Du
  • 669
  • 7
  • 15

2 Answers2

4

You'll have to find a way to discover the file type and pass it to the Lambda function as an argument. There isn't an alternative, here, with a pre-signed PUT.

The request signing process for PUT has no provision for wildcards or multiple/alternative values.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • Thanks for letting me know! I just wanted to make sure there wasn't a better way before I implement what feels like a 'hackish' solution. – Michael Du Apr 03 '17 at 21:03
2

In case anyone else is looking for a working answer, I eventually found out that react-s3-uploader does pass the content-type and filename over to the getSignin url (except I had forgotten to pass the query through in API Gateway earlier), so I was able to extract it as event.params.querystring.contentType in lambda.

Then in the params, I simply set {ContentType: event.params.querystring.contentType} and now it accepts all file formats.

Michael Du
  • 669
  • 7
  • 15