Search code examples
ruby-on-railsruby-on-rails-pluginspaperclip

paperclip private files


Is there a way to make paperclip attachments private? As in only where I explicitly want a user to be able to access a file, can the user access the file.

Obviously the file can't be in a public directory, but how do I get paperclip to check the user's access rights when trying to access that file to begin with?


Solution

  • PaperClip does not handle downloading the attachment. It only handles the uploading, processing and saving of the file.

    If you need something like this, you must save the photo in a private folder (or in DB, if this suits your needs). Then, you can implement a controller/action that will verify the user's credentials, read the file and then send the file as binary content.

    To send a binary content from the controller, you may want to check ActionController::Streaming API

    You may also want to check this thread on SO.