lambda-api icon indicating copy to clipboard operation
lambda-api copied to clipboard

Uploading files

Open rama41222 opened this issue 4 years ago • 4 comments

How to I handle files / multipart form data using lambda-api ?

  • I tried using multer and multer-s3 but it didn't work, I got req.pipe not found error

rama41222 avatar Jul 27 '20 22:07 rama41222

yes please, busboy is limited...multer rules on NodeJS. Please add support to that.

sebastianDejoy avatar Aug 25 '20 04:08 sebastianDejoy

Any insight about piping on this framework?

sebastianDejoy avatar Sep 28 '20 17:09 sebastianDejoy

Hi, were you able to process a multipart / form-data file? is it possible to do it with this library?

alejuanito avatar Mar 04 '21 16:03 alejuanito

Hey @alejuanito, yeap i was. The best approach is to use presigned urls that have a reasonable payload limit (50GB) as opposed to lambda/APIGW that is around 6MB.

I enabled an endpoint that return a presigned url:

const AWS = require('aws-sdk')

const s3 = new AWS.S3()
AWS.config.update({accessKeyId: 'id-omitted', secretAccessKey: 'key-omitted'})

// Tried with and without this. Since s3 is not region-specific, I don't
// think it should be necessary.
// AWS.config.update({region: 'us-west-2'})

const myBucket = 'bucket-name'
const myKey = 'test.pdf'
const signedUrlExpireSeconds = 3600;

const url = s3.getSignedUrl('getObject', {
    Bucket: myBucket,
    Key: myKey,
    Expires: signedUrlExpireSeconds
})

return url; //return this url as a value in your lambda response.

Then your API consumers (mobile aps) can upload whatever file they want through that presigned url: curl -v --upload-file ${fileName} ${presigned_url}

Make sure to grant access from your S3 bucket.

sebastianDejoy avatar Mar 04 '21 16:03 sebastianDejoy