Debugging
Your Uploaded Images Don't Survive on Vercel, and Committing Them to Git Isn't the Fix
Vercel's serverless filesystem is read-only except an ephemeral /tmp, so runtime image uploads don't persist. The cause, and the object-storage fix.
November 24, 2026
The upload route worked on my machine. I shipped it. The first image the site owner added was gone by the next request.
Start here: Vercel functions run on a read-only filesystem. Only
/tmpis writable, and it is ephemeral, so writing uploads intopublic/throwsEROFSor silently fails to persist. Send uploads to object storage (Vercel Blob or Bunny) and store the returned URL in your database. Swap the filesystemwriteFilefor a storageput().
The setup
The site has a small admin panel so its owner can add artwork and video thumbnails without touching code. The upload route accepts JPEG, PNG, or WebP up to 10 MB, runs the file through sharp, and names it <type>/<original>-<timestamp>-<random>.<ext>. The first version then wrote the result into the project's public/ folder, where it would be served as a static asset. Locally, this worked. Pick a file, hit save, and it shows up.
Then it went to production, and uploads stopped behaving.
The symptom
Two things can happen, depending on how you write the file, and both trace back to the same cause:
- The write throws outright:
EROFS: read-only file system, open '.../public/...'. - Or, if you wrote to the one writable location (
/tmp), the file works for a moment and then disappears. A later request cannot find it.
The tell is that it works in next dev and breaks only once deployed. That gap between local and production is the whole story.
The diagnosis
Vercel does not run your app on a long-lived server with a normal disk. Each request is handled by a stateless function, and that function's filesystem is read-only, except for a /tmp scratch space (up to 500 MB) that is ephemeral. Two consequences follow:
- You cannot write into
public/, or anywhere but/tmp, at runtime. That directory is baked at build time and read-only afterward, which is why you getEROFS. - Anything you write to
/tmpis neither durable nor shared. The next request may be served by a different instance that never saw your file, and instances get torn down. So/tmpis fine for "resize this one file and stream it back in the same request," and useless for "store this upload so it is there tomorrow."
This is why writing files from a serverless function is considered an anti-pattern. The function is supposed to be stateless, and persistent state belongs in a database or an object store.
"So I'll commit the images to git"
This is the trap worth naming, because it looks like it works. If you commit an image into the repo, it becomes part of the build output, and Vercel serves it without complaint. It does not vanish. As an upload mechanism, it falls apart:
- Every new image your user adds requires a commit and a redeploy. A non-technical site owner cannot do that.
- Your git history bloats with binary blobs forever.
- It defeats the point of a self-service admin panel.
So "commit to git" is not a persistence bug. It is a workflow dead end. The fix is to stop putting user uploads on the deployment filesystem at all.
The fix
Send uploads to object storage and save the returned URL in your database. The route's processing stays the same. Only the destination changes: you swap the filesystem write for a storage put().
Before (writes to the read-only deployment filesystem; breaks on Vercel). This version was replaced, so the block is reconstructed from the build log rather than copied from the repo:
import { writeFile, mkdir } from "fs/promises";
import path from "path";
const dir = path.join(process.cwd(), "public", "uploads");
await mkdir(dir, { recursive: true });
await writeFile(path.join(dir, filename), buffer); // EROFS in production
// ...then you'd store "/uploads/<filename>" in the DBAfter (writes to object storage; durable, served by URL). This is the shipped route, from the filename down:
import { put } from '@vercel/blob';
// ...
// Generate unique filename
const timestamp = Date.now();
const randomString = Math.random().toString(36).substring(2, 8);
const originalName = file.name
.replace(/\.[^/.]+$/, '')
.replace(/[^a-zA-Z0-9]/g, '-');
const filename = `${type}/${originalName}-${timestamp}-${randomString}.${extension}`;
// Upload to Vercel Blob
const blob = await put(filename, outputBuffer, {
access: 'public',
contentType,
});
return NextResponse.json({
success: true,
url: blob.url,
filename: blob.pathname,
size: outputBuffer.length,
});The caller stores blob.url in the database instead of a local path.
Two things that are not obvious the first time:
- Set
contentTypeon the upload. Without it, the browser may download the file or render it wrong instead of displaying it inline. - The value you persist is now a full URL on a different host, which is exactly what trips
next/imageon the next render. That is its own gotcha, written up separately in the companion piece on theunconfigured hosterror.
The deployment is immutable. Anything that changes after deploy, uploads and user data included, lives outside it. Once that is the default assumption, the upload route designs itself.
What I'd do differently
Decide where uploads live before writing the upload route, not after the first production failure. The moment a feature lets a user add a file, that file belongs in object storage or a database, never in public/. Treat the deployment as read-only by default, and this error never appears.
Stateless by default is not a restriction the platform imposes. It is the shape of the problem, and the filesystem error is the platform telling you so on the first request instead of the thousandth.
FAQ
Can't I write to /tmp?
Only for same-request scratch work, for example resizing a file and streaming it back within the same request. /tmp is ephemeral and not shared across invocations, so it will not be there on the next request.
Do images committed to git still work? Yes. They are static build output and serve fine. But committing every user upload and redeploying is not a workable upload flow for a self-service admin panel.
Does this affect API routes and server actions too? Yes. Anything running inside the function shares the same read-only filesystem. It is not specific to one route type.
Further reading
- Vercel — Functions Runtimes (states the read-only filesystem and the 500 MB writable
/tmp): https://vercel.com/docs/functions/runtimes - Vercel — How can I use files in Vercel Functions? (reading bundled files vs. writing at runtime;
process.cwd()guidance): https://vercel.com/kb/guide/how-can-i-use-files-in-serverless-functions - Vercel community —
EROFS: read-only file system(the canonical "why can't I write a file" thread, with the/tmpworkaround and the push toward persistent storage): https://github.com/vercel/community/discussions/314
Keep reading