Uploading images using netlify functions fails if images are too big

I created a form that uploads images to datocms securelly through netlify functions. Now this works quite good on local host, and mostly good when deployed. But when the image is larger than 400 kb, than the function doesn’t work and returns ‘unexpected token in json’. Now I found around that this might be a problem of the time limit of netlify functions, but what could be a solution? I’m currently encoding the image in base64.

Hi, @Fede.leuze. Have you looked at the function logs to see how long they function is running? I ask because the default time limit is 10 seconds. If they function is taking longer, we can extend the function time limit (for synchronous functions) to a recommended maximum of 26 seconds.

If you let us know the site subdomain or the site’s API id, our support team can increase that timeout.

Note, there is also a limit to the site of the POST request itself which is 6 MB imposed by AWS Lambda (which is the infrastructure that Netlify Functions is build upon). There is more information about Lambda limits here:

As the images stop working at only 400 KB, it does sound more likely that this is a timeout issue that a POST size issue. (As 400 KB is no where near 6 MB.)

About sending us the site subdomain or API ID, please feel free to post that information publicly or you can private message (PM) that to one of our support staff. I’ve confirmed that PMs are enabled for your forum login. Please keep in mind that only one person can see the PM and this will likely mean a slower reply than posting the information publicly. Please feel free to reply to however you prefer though.

Thank you, I do think that it’s a problem of time, as I saw that even if compressed it takes 14 seconds. I’ll write in private message to increase the time thanks. Then I’ll answer here again if this solves the problem

I’ll continue here, would it be possible to increase the timeout time of the netlify function? this is the website: https://vaalit.liikenyt.fi/

Hi, @Fede.leuze. I do see this resolved via a support ticket. If there are other questions though, please reply here anytime.

Was the timeout increased? Because it is still having problem with the same size of images

Hi, @Fede.leuze. The limit was increased to 26 but I don’t see any new deploys since that change. A new deploy is required for the change to take effect.

Would you please trigger a new deploy (it can be a redeploy of the same commit id) and then test the functions again? If they still are not working after the new deploy, please let us know.

Hi, yeah it’s still happening, is there any limit for the size of the request payload?

Hi @Fede.leuze,

The payload limit is 6 MB as mentioned. But you can try taking a look at: