Uploaded files disappearing after a deploy or restart
Short answer: If product photos, customer documents or generated invoices vanish after a deploy, a restart or a scaling event, your app is probably saving files to the server's local disk on a platform where that disk is temporary. Containers and many app platforms start each instance from a fresh copy of your code and throw away anything written while it ran. Store user uploads and generated files in persistent storage instead: an object storage bucket, a mounted persistent volume, or your platform's storage add-on. Then migrate any files that still exist, and test by restarting.
Why files disappear
On a traditional server, a file written to disk stays until someone deletes it. Modern hosting often works differently:
- App platforms. Heroku's documentation explains that each dyno gets its own ephemeral filesystem with a fresh copy of the most recently deployed code. Running processes can use it as a temporary scratchpad, but files written aren't visible to other dynos and are discarded the moment the dyno stops or restarts, including automatic restarts. Its Active Storage guide puts it plainly: you can write files to disk, but they won't persist after the application restarts.
- Containers. Docker's storage documentation explains that by default, files created inside a container are stored on a writable container layer, and data written there doesn't persist when the container is destroyed. Deploying a new version usually means replacing the container.
- Multiple instances. Even before a restart, a file saved by one instance isn't visible to another. A customer uploads a photo, the next request goes to a different instance, and the image is "missing".
Many frameworks default to local disk storage because it's simplest in development. That default quietly becomes a production bug.
Symptoms
- Uploaded images show as broken after the next deploy.
- Files appear and disappear depending on which page load you get.
- Generated PDFs or exports work, then return 404 hours later.
- Everything is fine in development, where there's one machine that never restarts.
Step 1: Find what writes to local disk
List everything your app writes:
- user uploads (product images, avatars, documents);
- generated files (invoices, reports, exports, thumbnails);
- caches and sessions stored as files;
- logs.
Check your framework's storage configuration and any code that writes to paths like uploads/, storage/ or public/media.
Step 2: Choose persistent storage
Object storage is the usual answer for uploads and generated files: a bucket service from your cloud provider or a compatible service. Heroku's Active Storage guide recommends a cloud file storage service such as Amazon S3 as the best practice. Benefits:
- shared by all instances;
- unaffected by deploys and restarts;
- can serve files directly or via a CDN;
- supports private files with time-limited signed links.
Persistent volumes. Docker's documentation describes volumes as persistent storage managed by Docker that retain data even after containers using them are removed. On a single-server setup, mounting a volume for uploads works. On platforms with many instances, a volume attached to one instance doesn't solve sharing.
Databases suit small structured data, not large files.
Most frameworks have storage libraries or settings that switch from local disk to object storage with configuration rather than code changes.
Step 3: Handle the other file types
- Sessions: use a database, cache service or signed cookies, not files.
- Caches: use a cache service; losing a cache on restart is acceptable, but it shouldn't break pages.
- Logs: send them to the platform's log stream or a logging service.
- Temporary files: fine on local disk, as long as nothing relies on them after the request.
Step 4: Rescue and migrate existing files
If some files still exist on running instances or in backups, copy them to the new storage and update database records that point to old paths. Tell customers if anything was permanently lost, and ask them to re-upload.
Step 5: Test
- Upload a file.
- Restart or redeploy the app.
- Check the file is still there and loads from every instance.
- Scale to two instances and check again.
Add this to your deployment checklist.
Backups for the new storage
Moving files to object storage doesn't automatically back them up. A deleted product photo or a bug that overwrites files can still lose data. Turn on versioning if your storage service offers it, so earlier copies can be restored, and include the bucket in your backup plan with copies kept in a separate account or location. Check that database backups and file backups are taken at similar times, so restoring one doesn't leave records pointing at files that don't exist.
Keep development realistic
Many of these bugs survive because development uses local disk while production uses something else. Where practical, point development and staging at a separate storage bucket too, or run a local service that behaves like object storage. Then a missing configuration setting shows up on a developer's laptop rather than in front of customers, and the same code path is tested every day.
An illustrative example
A hypothetical Kilkenny furniture maker launched a new shop on an app platform. Product photos uploaded by staff kept vanishing every day or two. The framework was saving uploads to the local storage folder, which the platform discarded on every restart and deploy. The developer configured the framework's storage to use an object storage bucket, re-uploaded missing photos from the staff's originals, moved sessions to the database and added a restart test to the deploy checklist.
FAQ
Can I just turn off restarts?
No. Platforms restart instances for maintenance and scaling. Design for it.
Is object storage expensive?
For most small businesses, storage costs are modest. Check your provider's pricing.
Should uploaded files be public?
Only if they're meant to be. Use private storage and short-lived signed links for invoices, ID documents and other customer files.
Do static site hosts have the same issue?
They don't run your code at all, so uploads need an external service anyway.
If files keep disappearing from your site or app after deploys, tell us where it's hosted.