But the gist is that I’m trying to parse an image upload from a function/lambda event and it doesn’t appear to be working. I’ve tried using busboy and also aws-lambda-multipart-parser. I can get a resulting buffer from both, but it seems to be malformed each time. I’ve tried checking the mime type with file-type and also trying to load the parsed image buffer into Jimp and get the following error: Could not find MIME for buffer (null). So it seems like, at least from these experiences, that part of the form data is getting malformed/dropped along the way.
Could you tell us more about your workflow? For instance, if you are using an event-triggered function you wouldn’t have any uploaded file data in the body - it would be a URL to the data. But perhaps you mean you wrote a function that accepts POSTs and you’re having trouble parsing the data directly off the wire?
Yup, it’s the latter! I’m posting directly to an endpoint. The errors I wrote about in the OP occur while running on Netlify/deployed to Lambda. Also when I use Netlify Dev the . parse.on('file', cb) never even occurs.
I don’t actually think that will work right now. I’ve opened an issue regarding adding support for multi-part requests to Netlify functions, and added a link to this thread so we’ll let you know once we have more info. Sorry about that @dmmulroy!
I ended up switching to straight up using API Gateway and Lambda and got https://www.npmjs.com/package/lambda-multipart working. Although my lambda function takes >29 seconds on images >650kb so I’m getting time outs so I’m rewriting from Node -> Go
I imagined 650kb to be trivial for node to handle, didn’t think it would’ve required rewriting to Go. Well, I didn’t imagine sending email with attachment to be a hassle too. PS: I’m a newer developer, devs on Twitter always talk about how easy it was to set up Rails back in the day. Sorry for ranting
Hey! @dmmulroy! I am also making a netlify function to accept a form with two images, I have converted them into base64 format. They are working properly in my local environment.
But in production I am getting a base64 encoded body, with the event.isBase64Encoded being true. None of that was happeining in local environment. And worst part is the body after decoding is partiall of what is sent.
We don’t use the lambda API gateway at Netlify, we run our own proxy. That said, you should be able to BASE64 encode your data and then decode it from within the function. Do you have a simple example repo that shows how the files are being uploaded and how you’re decoding them? You mentioned them being cut off, are you sending them back to the frontend?
Since we don’t support the binary media types setting on Netlify Functions you’d need to find a way to send the binary data by using plaintext.
The usual way this works is by encoding the payload via Base64.
The way the GraphQL multipart upload spec is designed (apollo-upload-client implements it) i don’t think you’ll be able to use it without adjustments on Netlify.
I don’t really have a solution to your problem, but will suggest not using upload-client but rather implementing file uploads just via fields in your mutation where the base64 encoded images go.