Next.js Discord

Discord Forum

413 Error : Payload Size Too Large on my next app deployed on vercel.

Answered
Yellow-horned horntail posted this in #help-forum
Open in Discord
Yellow-horned horntailOP
I am trying to upload videos to an S3 bucket from my next.js application using server actions. So the server action is called in my client component and takes in form-data as an argument, which is converted to a buffer then uploaded. Next limits this payload size to 20MB but of course this can be changed by adding configurations to your next.config.mjs file which I have done. And everything works fine (on my local machine) as I have been able to upload 20-30min long videos. So how do I configure the payload limit on the server action for my production app instance as well?
Answered by joulev
Body size limit of requests to Vercel is 4.5MB, this is a hard limit and you can’t do anything to increase that. So any files more than 4.5MB cannot be uploaded to Vercel.

What you can do is to generate a presigned URL instead, then send the file to that URL (the S3 backend) directly.
View full answer

7 Replies

Answer
Yellow-horned horntailOP
So essentially you are saying I have to create a presigned url to access the server action? Which would invariably mean I vould also try api/routes...
@Yellow-horned horntail So essentially you are saying I have to create a presigned url to access the server action? Which would invariably mean I vould also try api/routes...
No. The presigned URL is a URL for the s3 backend, not your backend. Look up presigned URLs.

Look up s3 presigned URLs.

The flow is this:
1. Generate a presigned URL with a server action
2. Send file to s3 with that URL
Yellow-horned horntailOP
Oh, I thought vercel had presigned urls or something. I'll check it out. But if you know any other ways to achieve it using server actions that be lovely.
If I create a next API route would it work or do you know if that limits payloads as well?
API routes won’t work. The file has to go directly to the s3 bucket, if you send it to Vercel first and then send it from Vercel to s3 you will bump into the 4.5MB limit no matter what you do.
Yellow-horned horntailOP
@joulev Thanks buddy, I just used presigned urls, it works fine