9
votes

I deployed my first Heroku app yesterday, and everything worked great.

In my app you can upload an image, I did and could see it on the "show" page. However, today the image disappeared. Everything else seems to work just fine. The application is working just fine on my local machine as well as on Heroku, other than the image which is not there.

What may be the problem? How can I make sure it doesn't happen again?

3

3 Answers

31
votes

Heroku does not support file uploads. The filesystem is readonly. You'll have to host your uploaded files somewhere else (or from the database, which is a bad option).

https://devcenter.heroku.com/articles/read-only-filesystem

Amazon S3 is a common choice: http://devcenter.heroku.com/articles/s3

If you are using any gems like paperclip or carrierwave for uploading, using S3 will be simple. You will have to set the S3 credentials in a config file and the gem will take care of uploading and will provide urls for the uploaded file.

10
votes

I suspect you may have uploaded the image to the Heroku filesystem and not an external filestore like Amazon S3. Heroku file system is temporary and not shared across dynos or restarts - which Heroku will do every day. I suspect this is what has occurred here resulting in you loosing your image.

2
votes

Heroku is file system is temporary. Alternative you can save the images as a url, until you are ready for aws...