D
D
Dmitry2014-11-26 10:45:26
Ruby on Rails
Dmitry, 2014-11-26 10:45:26

How to disable access to original images in Carrierwave?

Hello.
It is necessary to save the original images without a watermark. How can you restrict access from outside to the original images?

  1. You can change the name of the original file by adding the sha hash to it
  2. Change url for image versions

You can change the filename by overriding the filename method:
def filename
   "#{model.slug}.#{file.extension}" if original_filename.present?
end

But with this approach, the names of all images, including the original, change, and nothing prevents you from removing the version name from the link to the image and getting the original.
I rummaged through the carrierwave docks and did not find anything useful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vsuhachev, 2014-11-26
@warlockit

You need to prohibit using the settings of the web server that serves the files.
For example, rename all originals to original.* and close access to them

location ~* /original\.(gif|jpg|jpeg)$ {
  deny all
}

PS: example for nginx

J
Jeket, 2014-11-28
@Jeket

Create a folder inaccessible via http and upload files there. Example for paperclip:

Paperclip.interpolates :maybe_public do |attachment, style|
    style == :original ? "private" : "public"
  end


has_attached_file :image,  
 :styles => ....,
:path => ":rails_root/files/:maybe_public/:id_partition/:id/:style/:basename.:extension"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question