Store different versions of images in different places with Carrierwave

I was wondering if it is possible to store different versions of images in different places.

Let's say I have a Carrierwave personal folder defined as follows:

def store_dir
    "#{Rails.root}/private/uploads/"
end

And several versions of the uploaded images:

version :medium do
    process :resize_to_limit => [400, 400]
end

version :large do
    process :resize_to_limit => [800, 800]
  end

version :thumb do
    process :resize_to_limit => [200, 200]
end

I would like to save the downloaded image, middle version and large version of this image in a specific one store_path, but would like to have a thumb version for users stored in a shared folder, for example, inside this shared folder:

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

How can i do this? Thank!

+4
source share
2 answers

version_name, ,

def store_dir
  if version_name != 'thumb'
    # path for other versions
  else
    # path for thumb version
  end
end
+2

store_dir version. , ,

version :medium do
  process :resize_to_limit => [400, 400]
end

version :large do
  process :resize_to_limit => [800, 800]
end

version :thumb do
  process :resize_to_limit => [200, 200]

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

Source: https://habr.com/ru/post/1528813/


All Articles