0

I have made an app that lets users upload pictures and it works fine on my localhost but in heroku the pictures dont show. The picture stays on the heroku app for like an hour or two but then disappear (they also disappear if I click on "restart all dynos") after a few hours and says

2017-07-29T23:27:57.454817+00:00 heroku[router]: at=info method=GET path="/system/users/profileimages/000/000/003/thumb/adminimage.png?1501366211" host=my-app-75380.herokuapp.com request_id=b3eb34d9-9783-420f-9f3d-ad05fdbe5ebb fwd="207.38.188.8" dyno=web.1 connect=0ms service=7ms status=404 bytes=1902 protocol=https

When I inspect it in chrome, I get

Failed to load resource: the server responded with a status of 404 (Not Found)

Is there a limit of number of pictures you can upload on heroku apps? And do the size of the images matter? Or does it have anything to do with asset pipeline?

craftdeer
  • 985
  • 5
  • 20
  • 36
  • 1
    You cannot save images to folders on Heroku. You need to upload them to a service like AWS or something. The answers here might help you understand the issue https://stackoverflow.com/questions/16210486/picture-disappeared-on-heroku – Rockwell Rice Jul 29 '17 at 23:58
  • Wow really? I didn't know that. But I just uploaded two images on heroku. I think it is only letting me upload two entries, that is, two columns in the database. – craftdeer Jul 30 '17 at 00:01
  • 1
    No, those images will disappear, do a push of code for example and you will notice they are gone. – Rockwell Rice Jul 30 '17 at 00:02
  • ahh, okay cool thanks. I was looking into AWS but it asked for my credit card credentials and I didnt want to pay. It may be off the topic but does uploading maybe 10-30 images cost money on AWS? – craftdeer Jul 30 '17 at 00:04
  • 1
    No that should not be an issue. I host two sites there and am still in the free tier, you can also set a limit on your account so it does not blow up (if it gets hacked or something) without you knowing and all of the sudden you have a $100 bill or something, I would recommend doing that. – Rockwell Rice Jul 30 '17 at 00:06

1 Answers1

1

Here is a good explanation of what is happening from Heroku's documentation:

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted. For example, this occurs any time a dyno is replaced due to application deployment and approximately once a day as part of normal dyno management.

I'd recommend following the instructions on this page to get Paperclip, Heroku, and Amazon S3 all working together.

smudge
  • 801
  • 1
  • 6
  • 21
  • Understood. I never quite understood where all the files would be saved when uploaded. That cleared a lot of things. ty – craftdeer Jul 30 '17 at 03:12