How to fix Vercel 413 FUNCTION_PAYLOAD_TOO_LARGE on file uploads
Send large files directly to private storage. Use Vercel Blob for storage-only uploads, or keep Next.js on Vercel and verify the file on Gregale.
To fix Vercel’s 413 FUNCTION_PAYLOAD_TOO_LARGE on file uploads, send the file
directly from the browser to storage. Have your Next.js route authenticate the
user and issue a short-lived upload URL. Keep the file bytes out of your Vercel
Function. If the file only needs storing, start with
Vercel Blob client uploads.
If your app needs a separate runtime to validate or process the file, keep
Next.js on Vercel and run that work next to private storage.
Vercel documents a 4.5 MB default request-body limit.
Eligible Node.js, Python and Bun Functions with Fluid Compute and Performance
(4 GB) memory can opt in to a 20 MiB public beta using
VERCEL_SUPPORT_LARGE_REQUEST_BODY=1.
An 8 MiB upload exceeds the default, not that opt-in limit. A qualifying opt-in
can help when requests truly need to land in the Function, but it does not
change where your upload bytes travel.
Choose the simplest upload path
| Job | What to do |
|---|---|
| Store a file | Use @vercel/blob/client and its authenticated token exchange. |
| Run custom validation or file processing | Upload directly to a private bucket. Pass an object reference or intent to a worker. |
| Send an unusually large JSON request | Check the opt-in beta for the exact deployed runtime and memory class, or redesign the payload. |
For Blob, use the browser’s upload() helper and the server’s handleUpload()
token exchange. Authorize the user before issuing a token. Use a private Blob
store if the files are private; a hard-to-guess public URL is not access
control. Do not replace the Function with a different server-side upload
handler and leave the browser posting the same large body to Vercel.
Keep Next.js on Vercel and verify the upload on Gregale
Download the Next.js app, verifier and local test.
- Sign. Next.js sends only file length and SHA-256 to a separate Node
service. Once authorized, the service generates a new object key under
incoming/and creates a signed PUT for that key, declared size and operation. The sample uses a two-minute capability and a create-only precondition, so it cannot overwrite an existing object. - Upload. The browser sends the
Filedirectly to the private bucket. Copy the returned signed headers exceptContent-Length, which the browser derives from the file. Set bucket CORS for the exact frontend origin and the required PUT headers. No Gregale key goes to the browser. - Verify. The browser submits the signed intent, not the file or a
client-chosen URL. The worker opens the designated object, reads it in
chunks, checks length and SHA-256, and writes a create-only receipt to
receipts/<id>.json. A retry with the same unexpired intent returns the recorded result. A failed check does not produce a success receipt.
The sample accepts up to 12 MiB and holds each metadata request to 2 KiB. Check Gregale storage limits and availability for your account and test the private bucket before relying on it. The example uses read and write grants on one test bucket; it does not require managed object-created delivery. If you need longer processing, move verification behind a durable queue or an eligible object-created trigger and return a job ID instead of keeping Next.js waiting. For files larger than your storage provider’s single-PUT limit, use resumable multipart upload.
Before using real data, replace the demo shared key with authenticated, owner-bound intents and quotas. Expire abandoned uploads, avoid logging signed URLs, and scan or quarantine untrusted content as appropriate. A SHA-256 match does not tell you whether a file is safe to open.
Reproduce the cutoff and check the fix
Make the synthetic file from the bundle README. If you still have a
disposable hosted Vercel preview of the old raw-file route and it uses the
default limit, send the 8 MiB body to that route and look for HTTP 413 and
FUNCTION_PAYLOAD_TOO_LARGE. Return less than 4.5 MB from the route to
avoid testing the separate response-body limit instead. Developer controls
such as Next.js body parsing do not raise Vercel’s platform limit.
Then upload the same file through the direct path. In your browser’s
Network panel, only the PUT to the storage origin should contain the
8,388,608-byte file. The two Next.js requests should contain only JSON.
The final receipt should report the same length and SHA-256 as your
original file. A storage error or verifier rejection is not a successful
upload, even if the initial signing request returned 200.
What we verified
We ran the Next.js app locally with a separate Node verifier and a private loopback storage emulator. A browser sent 8 MiB directly to storage, with two metadata-only requests to Next.js (93 and 267 bytes), and got the expected byte count and SHA-256. Automated tests also checked that an upload URL cannot read the object or overwrite it, completion before upload fails, same-length content with the wrong SHA-256 is rejected, and another worker returns the same receipt for a retry.
The local emulator exercises the protocol, not real S3 or Gregale storage. We did not run a hosted Vercel 413 repro or a hosted Vercel-to-Gregale upload.
Questions
- What is the Vercel Function upload limit?
The default request limit is 4.5 MB. Eligible Node.js, Python and Bun Functions with Fluid Compute and Performance (4 GB) memory can opt in to a 20 MiB public beta.
- How do I upload a file larger than the Vercel Function limit?
Upload directly from the browser to storage with a scoped upload capability. Use Vercel Blob client uploads if you only need to store the file.
- Can I keep Next.js on Vercel when a file needs custom processing?
Yes. Keep Next.js as the frontend, upload directly to a private bucket, and send a small intent or object reference to a separate worker that verifies and processes the stored object.