Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Paperclip expiring_url with S3 :permission => :private
    primarykey
    data
    text
    <p>I am creating a Rails app where a User uploads a file to S3 using Paperclip and which then a separate group can download the uploaded files. I need the files to be private and have been trying to use :permissions => :private without any luck, but can upload and download files in a with this turned off.</p> <p>I have been following the github issue: <a href="https://github.com/thoughtbot/paperclip/wiki/Restricting-Access-to-Objects-Stored-on-Amazon-S3" rel="nofollow noreferrer">https://github.com/thoughtbot/paperclip/wiki/Restricting-Access-to-Objects-Stored-on-Amazon-S3</a> and <a href="https://stackoverflow.com/questions/3897837/rails-3-paperclip-s3-howto-store-for-an-instance-and-protect-access">Rails 3, paperclip + S3 - Howto Store for an Instance and Protect Access</a> but am still stuck and would appreciate some help. Here is what I have so far:</p> <p><strong>model/user.rb</strong></p> <pre><code>class User &lt; ActiveRecord::Base has_many :parts ... if Rails.env.development? has_attached_file :model else has_attached_file :model, :storage =&gt; :s3, :path =&gt; "files/:id/:basename.:extension", :default_url =&gt; '/images/missing_:style.jpg', :bucket =&gt; ENV['AWS_BUCKET'], :s3_permissions =&gt; :private, :s3_host_name =&gt; 's3-us-west-1.amazonaws.com', :s3_credentials =&gt; { :access_key_id =&gt; ENV['AWS_ACCESS_KEY_ID'], :secret_access_key =&gt; ENV['AWS_SECRET_ACCESS_KEY'] } end </code></pre> <p><strong>user_controller.rb</strong></p> <pre><code> def create @user = User.new(params[:user]) @part = Part.new if @user.save ... end end def download @user = User.find(params[:id]) redirect_to(@user.model.expiring_url(10)) end </code></pre> <p><strong>part_controller.rb</strong></p> <pre><code>class PartsController &lt; ApplicationController def index @parts = Part.all @users = User.all end end </code></pre> <p><strong>routes.rb</strong></p> <pre><code> match 'users/download' =&gt; 'users#download', :as =&gt; 'download_model' </code></pre> <p><strong>parts/index.html.erb</strong></p> <pre><code>&lt;p&gt; &lt;% @parts.each do |part| %&gt; &lt;p&gt;&lt;%= part.model_name %&gt;&lt;/p&gt; &lt;% end %&gt; &lt;% @users.each do |user| %&gt; &lt;p&gt;&lt;%= link_to "Download", download_model_path(user) %&gt;&lt;/p&gt; &lt;% end %&gt; &lt;/p&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload