lambda-api
lambda-api copied to clipboard
Uploading files
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
yes please, busboy is limited...multer rules on NodeJS. Please add support to that.
Any insight about piping on this framework?
Hi, were you able to process a multipart / form-data file? is it possible to do it with this library?
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.