Why do uploaded pictures disappear on Heroku?
Asked Answered
G

3

9

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?

Gilolo answered 25/4, 2013 at 8:57 Comment(0)
C
32

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.

Calipee answered 25/4, 2013 at 9:5 Comment(0)
A
11

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.

Abilene answered 25/4, 2013 at 9:5 Comment(0)
E
2

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

Excitant answered 30/12, 2020 at 2:41 Comment(1)
Hello and welcome to SO! Please take the tour and read How to Answer. Please try to provide additional data over the existing answers. Try to give examples so the reader can easily understand.Legitimatize

© 2022 - 2024 — McMap. All rights reserved.