Note that there are some explanatory texts on larger screens.

plurals
  1. POPaperclip different styles with different permissions
    primarykey
    data
    text
    <p>I have a GalleryPhoto model with a paperclip attachment that gets processed into a number of styles. Some styles need to be publicly readable; some need to be private.</p> <p>Here's my model:</p> <pre><code>class GalleryPhoto &lt; ActiveRecord::Base has_attached_file :image, :storage =&gt; :s3, :bucket =&gt; ":bucket.myapp_#{Rails.env == 'production' ? 'production' : 'development'}", :path =&gt; "images/galleries/:gallery_id/:id/:style_:id.:extension", :url =&gt; "/images/galleries/:gallery_id/:id/:style_:id.:extension", :s3_credentials =&gt; { :access_key_id =&gt; 'XXXXXXXXX', :secret_access_key =&gt; 'XXXXXXXXX' }, :s3_permissions =&gt; { :thumbnail =&gt; :public_read, :small =&gt; :public_read, :medium =&gt; :public_read, :large =&gt; :public_read, :small_download =&gt; :private, :original =&gt; :private }, :styles =&gt; { :thumbnail =&gt; { :geometry =&gt; "80x80&gt;" }, :small =&gt; { :geometry =&gt; "200x200&gt;" }, :medium =&gt; { :geometry =&gt; "400x400&gt;" }, :large =&gt; { :geometry =&gt; "600x600&gt;" }, :small_download =&gt; { :geometry =&gt; "600x600" } } end </code></pre> <p>Here's my paperclip initializer:</p> <pre><code>Paperclip.interpolates :bucket do |attachment, style| [:original, :small_download].include?(style) ? "private" : "public" end Paperclip.interpolates :gallery_id do |attachment, style| attachment.instance.gallery_id end </code></pre> <p>I have four buckets as such:</p> <pre><code>private.myapp_development private.myapp_production public.myapp_development public.myapp_production </code></pre> <p>The private.xxx buckets shouldn't be publicly accessible, but the public.xxx buckets should be publicly readable.</p> <p>I can get the app to serve the styles that have been marked public in the public buckets, but I cannot do uploads or have my download action, which serves the private styles, work.</p> <p>Here's the log when I try to do an upload:</p> <pre><code>[paperclip] Saving attachments. [paperclip] saving images/galleries/242/22034/original_22034.jpg (0.8ms) ROLLBACK Completed 500 Internal Server Error in 8013ms Errno::EPIPE (Broken pipe): app/controllers/gallery_photos_controller.rb:13:in `create' </code></pre> <p>Here's the log when I try to use my download action for the private styles:</p> <pre><code>Sent file images/galleries/222/19515/original_19515.jpg (0.2ms) Completed 500 Internal Server Error in 861ms ActionController::MissingFile (Cannot read file images/galleries/222/19515/original_19515.jpg): app/controllers/gallery_photos_controller.rb:22:in `download' </code></pre> <p>What am I missing?</p> <pre><code>rails 3.1.1 paperclip 2.7.0 aws-sdk 1.3.7 </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.
 

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