I am building a site where I want to protect certain images from download. Only authorized users would be able to download them.
As I upload images with Carrierwave, they are stored inside public/uploads/image
. Users can download them via link:
def transmit
send_file(Rails.root.join('public' , 'uploads', 'image', filename.to_s)
end
How can I protect images inside image
folder so unauthorized users can't access them? Let's say users
table has boolean column authorized
.
What would be the best way to do it?
EDIT1:
I know I can make before_action
which wont allow unauthorized user to download it via download link but the image is still accessible if the user knows path to the folder where are images stored.