Issue
Files are uploaded to the app but then disappear or are deleted after a while.
Resolution
The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy. This is similar to how many container based systems, such as Docker, operate.
In addition, under normal operations dynos will restart every day in a process known as "Cycling".
These two facts mean that the filesystem on Heroku is not suitable for persistent storage of data. In cases where you need to store data we recommend using a database addon such as Postgres (for data) or a dedicated file storage service such as AWS S3 (for static files). If you don't want to set up an account with AWS to create an S3 bucket we also have addons here that handle storage and processing of static assets https://elements.heroku.com/addons
We have some language-specific documentation on handling uploads here:
For Ruby/Rails apps
- https://devcenter.heroku.com/articles/paperclip-s3
- https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails