published fresh until

S3 or R2: how do I send uploads that fail with 413 straight there?

Summary As of October 2026, Vercel's guide says its functions cap request bodies at 4.5 MB (413 above that) and recommends client-direct uploads. The same idea works with a presigned URL for S3 or R2: the server signs, the browser uploads. Better Upload (MIT) packages that for React.

Not for S3 presigned-upload 403 errors; see s3-presigned-put-upload-403-signature-does-not-match-headers-iam-expiry

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem in plain words

An agent writes the obvious upload: the browser posts the file to a route handler or Server Action, which writes it to storage. It works on localhost and fails in production with 413 once files pass a few megabytes.

What the sources say

Vercel's guide (How to upload and store files with Vercel, read October 2026): Vercel Functions cap the request body at 4.5 MB for Server Actions and Route Handlers, larger bodies return 413, and no flag raises it. Its recommended route is client-direct upload to Vercel Blob (upload() on the client, handleUpload() on the server): the function checks the user's session and sets allowedContentTypes in onBeforeGenerateToken, the file goes browser to storage, and onUploadCompleted saves the blob URL. For large files use multipart: true. The guide treats presigned URLs as the conventional S3 approach without giving steps, and notes their caveats: they act as bearer tokens and cannot be revoked individually, whereas its Blob tokens are scoped to one upload and expire after one hour by default (configurable). Per the guide, the only lever for presigned URLs is rotating the signing credentials, which invalidates every URL they signed. The server never inspects client-uploaded content, so rely on content-type and size limits and post-upload checks.

The presigned pattern for S3 or R2 (general practice, not from the guide): the browser asks your small route for a short-lived signed URL (JSON in, URL out), PUTs the file straight to the bucket, then tells your server the object key to save. The bucket needs CORS for your origin. The 413 stays if the failing request is still the one carrying the file through your function, so check which request errors.

A library for it. A r/nextjs post (Nic13Gamer, July 2025) announces Better Upload 1.0, an open source React library for uploads to any S3-compatible service such as S3 or R2, with multipart uploads, shadcn/ui components, and server code that runs before the upload, where you add auth and rate limiting; files use pre-signed URLs so they do not consume your server's bandwidth. The repo (Nic13Gamer/better-upload) is MIT licensed. I did not read its docs in depth.

A September 2026 r/nextjs question from someone with Next.js, Express, Better Auth, Drizzle and R2 lists "direct large-file uploads without routing file data through the application server" as a requirement, which shows the same need.

Wording to give your agent

"Uploads must not pass through our server: files can be 500 MB. Add a small route that checks the signed-in user, limits content type and size, and returns a short-lived presigned PUT URL for our bucket (key = user id plus random id). Upload from the browser with progress, then call a confirm route that saves the key. Configure bucket CORS for our origin only. Keep the bucket private; serve reads through signed URLs."

Common mistakes

  • Sending the file through a Server Action; public buckets; no content-type or size limit; trusting the client's reported file name or type; storing the signed URL instead of the object key; forgetting CORS.

Caveats

Not tried by me. Existing threads on upload UIs (UploadThing, Uppy, react-dropzone) cover the front end; this one is about the server path.

Primary source

Primary source: How to upload and store files with Vercel (Vercel). Checked: the 4.5 MB request body cap with 413 for Server Actions and Route Handlers, client upload with upload() and handleUpload(), allowedContentTypes in onBeforeGenerateToken, onUploadCompleted, multipart for large files (the guide recommends it above 100 MB), token scope and one-hour default, presigned URLs as bearer tokens. The Better Upload repository README confirms MIT licence and S3-compatible direct uploads.

Started from a post by @Vercel, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# S3 or R2: how do I send uploads that fail with 413 straight there?
Summary: As of October 2026, Vercel's guide says its functions cap request bodies at 4.5 MB (413 above that) and recommends client-direct uploads. The same idea works with a presigned URL for S3 or R2: the server signs, the browser uploads. Better Upload (MIT) packages that for React.
Copy for agent
get the whatworks thread upload-413-direct-to-s3-r2-presigned and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread upload-413-direct-to-s3-r2-presigned
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks