1

Currently when I store any image using shrine uploader then I received url :-

/uploads/store/90bcb5a78ed5de16a6c62eea1fb80ed1.png

but I want url to be display like:-

/uploads/store/original_image_name.png

is there any solution

for reference:-

initializer/shrine.rb

require "shrine/storage/file_system"
  Shrine.storages = {
    cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"),
    store: Shrine::Storage::FileSystem.new("public", prefix: "uploads/store")
  }

model/image_uploader.rb

class ImageUploader < Shrine
  plugin :derivatives
  plugin :url_options, store: { host: "www.cloudfair.com" }
  Attacher.derivatives_processor do |original|
    processor = ImageProcessing::MiniMagick.source(original)
    {
      large:  processor.resize_to_limit!(1280, 800),
      medium: processor.resize_to_limit!(600, 600),
      small:  processor.resize_to_limit!(400, 400),
    }
  end
end

to upload image:-

photo = Photo.new
photo.image = params[:image_file]
photo.image_derivative!
photo.save()

to access image URL:-

photo.image(:small).url
3
  • Could you include the code you're using to upload the image? Commented Jun 2, 2020 at 8:34
  • Sure, I will update it within 5 min Commented Jun 2, 2020 at 8:47
  • code updated... please check Commented Jun 2, 2020 at 8:54

1 Answer 1

1

you can use something like this in your uploader file

def filename
  if original_filename
    "#{model.original_filename}.#{file.extension}"
  end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.