Load default image on s3 using carrier
We use carrierwave gem
rails to load our images into the project. We need to support creating a non-image object, but the application will work across multiple platforms, and we don't want to support non-image objects on all platforms, so we want to have a default image.
So this was the first decision
class IconUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
def store_dir
"uploads/#{model.id}"
end
def default_url
"/images/icons/" + [version_name, "default.png"].compact.join('_')
end
version :thumbnail do
process resize_to_fill: [200, 200]
end
version :high_resolution do
process resize_to_fill: [400, 400]
end
end
The problem is that all devices will come to the server (not S3) looking for this default image. At the same time, this is a problem with multiple versions of the image.
So this is the second solution:
class CategoryController < ApplicationController
...
def create
@category = Category.new(category_params)
@uploader = IconUploader.new(@category, :icon)
uploader.cache!(File.open("app/assets/images/photos/picture.jpg"))
@category.image=@uploader
@object.save
end
...
end
This solves the problem of multiple resolutions and always goes to S3 to get the image. But the problem is that it will duplicate the default image on S3 many times.
Our third solution might be to use the already generated image on Amazon as the default url, but it has the same versioning issue that we won't even implement it.
Can you think of a better solution to this problem?
source to share
No one has answered this question yet
Check out similar questions: