This repository was archived by the owner on Jul 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Hashing
pierce-h edited this page Sep 30, 2014
·
10 revisions
To secure your attachments by hiding the actual directory structure from prying eyes.
Add an initializer:
# config/initializers/paperclip_defaults.rb
Paperclip::Attachment.default_options.update({
:path => ":class/:attachment/:hash/:style.:extension",
:hash_secret => ENV[RANDOM_SECRET],
:hash_data => ":class/:attachment/:id/:style/:updated_at"
})The :hash interpolation is generated from :hash_secret and the pattern given by the :hash_data option, which by default is ":class/:attachment/:id/:style/:updated_at", as shown.
Generate the :hash_secret using SecureRandom.base64(128) from a rails console to generate a relatively secure random string.
Once you've got that set up, defining attachments requires no modifications to get the new hashing behavior:
class Profile
has_attached_file :portrait
end