On my website i have a form that uses multipart to send text with files
This multi-part data is going to nextjs api and then to my backend, so in the end it looks like so
client → nextjs api route → backend api route
When i’m sending form without files or with files that are less than 4 mb everything works as expected,
but when i’m trying to send files that are larger than 4mb, it suddenly fails with following errors
SyntaxError: Unexpected token '<', "<HTML>
<HE"... is not valid JSON
if i go to network and look there, then it says “Sever closed connection”
or
SyntaxError: Unexpected end of JSON input
Which has empty response on network tab
What am i doing wrong? i’ve heard about 4mb limit in nextjs, but i’ve changed it like so
If i understand correctly this only applies to forms that use data-netlify=true which i don’t use, i have a regular form that sends data to NextJS backend api which then gets redirected to my backend
The files are also likely being base64 encoded by the browser before being sent which also makes them larger. This is why a file smaller than 6 MB is hitting the limit (because it is over 6 MB after the base64 encoding).
This is my best guess as to why the large file uploads are failing.
The primary solution for this is to not use AWS Lambda for the form. If Lambda is used, this limitation will always exist.
Thanks, i knew something was not working on netlify side or i was hitting the limit, but wasn’t able to find what exactly it was, now it all makes sense, so i guess if i want to handle uploads up to 20MB i have to use my backend route directly from client and there is no other way for this to work?
Hi @isnas , sorry to say there isn’t a way to upload up to 20MB using form submissions as Luke mentioned, the Next.js API route is using Netlify Functions which are in turn using AWS Lambda which has the 6MB limitation.