Shalafister's
Shalafister's

Reputation: 881

Rails rmagick gem on heroku can not find pictures

I have a rails app, where users can upload car pictures then I show them on a slider. I am using Carrierwave and RMagick.

I have pushed my app to heroku and uploaded some car pictures as well as user profile picture.

At first, heroku shows pictures perfectly but at some time later, Heroku gives a load error on uploaded pictures (404 not found error).

I think that might because of the RMagick because when I push the app it gives warning RMagick is depreciated require rmagick instead.

my image_uploader.rb file;

# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base


  include CarrierWave::RMagick


  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :large do
    process :resize_to_fill => [327, 282] 
  end

  version :mid do
    process :resize_to_fill => [217, 141] 
  end


end

The pictures are saved under public/uploads/picture/image/1/car_mid.png

EDIT:

Maybe that might be a problem?. I am using free account for now for Heroku. Heroku not saving uploaded pictures. But when I upload I see pictures then after a while they disappear.

EDIT2:

I have restarted the heroku app by heroku restart command right after I uploaded some car pictures and those pictures are disappeared (404 not found). So, do you think the problem is because I use free account with 1 dyno?

Upvotes: 0

Views: 87

Answers (1)

Uzbekjon
Uzbekjon

Reputation: 11813

The filesystem on Heroku is not persisted. Only files uploaded through deployment mechanisms (git push) are "persisted". Others like the ones in your public folder will be erased. That's why they are disappearing.


I have answered a similar question here. Here is a quote:

Your dyno on Heroku has a "read-only" filesystem. In a sense, your files will not be persisted between your dyno restarts and there is no guarantee that they will persist between any two requests. Here is an excerpt from the docs:

Each dyno has its own ephemeral file system, not shared with any other dyno, that is discarded as soon as you disconnect. This file system is populated with the slug archive so one-off dynos can make full use of anything deployed in the application.

You can use the #{Rails.root}/tmp folder as temporary folder, but you need to upload your files to some external storage (S3, some CDN, etc.). Heroku has some addons that makes it easy to handle.

Upvotes: 1

Related Questions