Uploading file via form to netlify function

Site name: https://focused-joliot-86e973.netlify.app/
Domain: havent set up domain yet

Hello, since i want to do some custom things when a form is submitted on my site, I am submitting the forms via axios posting to a Netlify function. This has worked with the first four forms that I have made, but I am having trouble with the html input “file” type. I am successfully saving the value as the file content, but when i send over the data to the lambda function, it is just showing up as an empty object (that is what the value is initialized to before the form is filled out)

I’m obviously not asking for any help with customized code, my main question is, is it possible to upload a file to a function via a form input field? I understand that they are serverless functions and i could see that not being possible, but i am a fairly new developer and lack the complete understanding to know that for sure. My main goal is to upload the file via a form and attatch those files to an email with nodemailer and am just wondering if this is possible. Thank you!

hi there, did you see these posts already? there are very likely some ideas in there for you!

I did see a couple of these while researching, but not all of them so i’ll take a look, thank you! Also i do think i am making some progress in this, but is there a maximum post payload for local development? I am getting “Stream body too big” when i submit my form with 5MB of files

Edit, i am also getting an “Unexpected end to JSON” error when trying to submit the form in production. I image it is because there is some sort of payload limit on the post request and my 5MB is hitting that limit

After further research, it seems like AWS lambda functions have a payload limit of 6MB, i must have been hitting 6 instead of 5 like i assumed. Because of this, i assume the payload limit for netlify functions is the same?

I found this forum: Function max request payload size?
But it didnt seem to be confirmed that 6MB is the real limit, i can’t find it anywhere in the docs, do you know by chance?

I ended up just spinning up a small express app on heroku and handling this particular form that way and it works great, it would still be nice to confirm the max payload for functions are 6MB, but other than that, i will mark as resolved :slight_smile:

AWS has a specific limit, which we cannot exceed (or rather, which you can try to exceed, and receive errors such as you got):

https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html

Note that in many cases, what you submit is encoded in some way that causes it to represent larger on the wire than it may on the filesystem, so you’ll need to take that into account when planning to use functions.

1 Like

Yes i did notice that, i had converted the files to base64 and it increased the payload size by 33%, good to know for anyone else trying to do this

1 Like