umezo
umezo

Reputation: 1579

Newly uploaded images break in production but not in development

I would appreciate any feedback regarding what may be causing my issue, described below.

I have an application that allows users to upload images. Everything works fine in development and used to work fine in production.

Recently, my newer images have all broken. I can upload new images, but when I check back a few hours later, the images are broken again. This started happening about a week ago, and images that I've had up in production from before then are still ok.

I am using Rails with Bootstrap and SimpleForm, and using Paperclip for the images. I am using Postgres in both devleopment and production, and am deploying to Heroku.

The only hint I have is in the "blank_profile_pic.png" image that I use as a default when users don't have a profile picture uploaded.

User.all.each do |u|
  if u.profile_pic.file?
    image_tag(user.profile_pic)
  else
    image_tag("blank_profile_pic.png")
  end
end

For users that don't have a profile_pic uploaded, a broken image appears if their profile was created in the last week, but the expected "blank_profile_pic.png" remains for people that created their account before the issues started surfacing a week ago. How can the same block of code return different results between recent and older users?

I really don't know where to start with this, so would appreciate any feedback regarding what possible causes could be, and if there are any other files that I can show here.

Thanks very much for your help!

Upvotes: 0

Views: 194

Answers (2)

AmitF
AmitF

Reputation: 1457

I am not sure if you have the imagemagick gem installed, but we had same issue with image_magic that was breaking our paperclip functionality in production, but not in development (weird, I know). Yet even after removing imagemagick from our gemfile and Gemfile.lock locally (running bundle install and all that stuff) and then deploying back to production on heroku, the error persisted in production! (weird, I know).

What ended up doing the trick was running:

$ heroku repo:purge_cache -a myAppName

(Taken from: https://github.com/heroku/heroku-repo#purge_cache)

When you deploy your app, Heroku caches some things like your assets and installed gems in order to speed up deployment. Although this is a great feature, it can have side-effects sometimes, and in this case, it seems that something about the imagemagick gem got "stuck" in production's cache, which is why purging solved the issue for us (since after purging, your app will rebuild itself from scratch on your next deployment)

Upvotes: 0

Benjamin Tan Wei Hao
Benjamin Tan Wei Hao

Reputation: 9701

Heroku is a read only system. So you most definitely have to upload your images either to S3 or some other cloud provided.

Your images might have been uploaded to /tmp in Heroku and then somehow it was cleared, hence the errors.

Here are the docs: https://devcenter.heroku.com/articles/read-only-filesystem

And configuring Paperclip with S3: https://github.com/thoughtbot/paperclip#storage

Upvotes: 1

Related Questions