Server Action doesn't work when submitting files over 4.5 MB
Answered
MooKorea posted this in #help-forum
MooKoreaOP
I created a form on my website that allows users to add up to 4 images, and I'm using the Imgur API to turn those images into links. I'm using a server action to keep my API key secure on the server. However, I'm running into an issue where if the file size exceeds 4.5 MB it doesn't work. The documentation here says I can increase the size limit in API routes, but it doesn't mention anything about server actions: https://nextjs.org/docs/messages/api-routes-response-size-limit. Is there no way to increase the file size limit for server actions?
Answered by joulev
but Vercel the platform does not allow serverless functions (like server actions) to receive payloads larger than 4.5MB
12 Replies
@MooKorea I created a form on my website that allows users to add up to 4 images, and I'm using the Imgur API to turn those images into links. I'm using a server action to keep my API key secure on the server. However, I'm running into an issue where if the file size exceeds 4.5 MB it doesn't work. The documentation here says I can increase the size limit in API routes, but it doesn't mention anything about server actions: https://nextjs.org/docs/messages/api-routes-response-size-limit. Is there no way to increase the file size limit for server actions?
no, impossible. the 4.5MB limit on vercel is a hard limit enforced on the architectural level, there is no way around it.
from what you are trying to do, it looks like you should get a normal server and deploy your app on it – serverless platforms won't do well here.
from what you are trying to do, it looks like you should get a normal server and deploy your app on it – serverless platforms won't do well here.
Asian black bear
Or upload to S3/R2 directly from the client via a presigned URL.
MooKoreaOP
shoot, I guess I'll use the imgur API on the frontend then
@Asian black bear Or upload to S3/R2 directly from the client via a presigned URL.
they are using the imgur API, this is not applicable to them
Asian black bear
Oh I missed that detail, indeed.
MooKoreaOP
wait, the documentation here says it can be increased https://nextjs.org/docs/app/api-reference/next-config-js/serverActions
since the current file size limit on my images is 4MB, is it not too far-fetched to simply set the bodySizeLimit to 16MB?
but Vercel the platform does not allow serverless functions (like server actions) to receive payloads larger than 4.5MB
Answer
if you self-host, sure, you can make it 16GB if you want, but on Vercel 4.5MB is the best you can do
MooKoreaOP
the site is hosted on Netlify actually
i doubt netlify will do much better since it's still serverless and serverless has certain fundamental limitations
but you can try