Paper clips of different styles with different resolutions

I have a GalleryPhoto model with a paperclip app that is handled in multiple styles. Some styles need to be publicly available; some of them must be private.

Here's my model:

class GalleryPhoto < ActiveRecord::Base
  has_attached_file :image,
    :storage => :s3,
    :bucket => ":bucket.myapp_#{Rails.env == 'production' ? 'production' : 'development'}",
    :path => "images/galleries/:gallery_id/:id/:style_:id.:extension",
    :url => "/images/galleries/:gallery_id/:id/:style_:id.:extension",
    :s3_credentials => { :access_key_id => 'XXXXXXXXX', :secret_access_key => 'XXXXXXXXX' },
    :s3_permissions => {
      :thumbnail => :public_read,
      :small => :public_read,
      :medium => :public_read,
      :large => :public_read,
      :small_download => :private,
      :original => :private
    },
    :styles => {
      :thumbnail => {
        :geometry => "80x80>"
      },
      :small => {
        :geometry => "200x200>"
      },
      :medium => {
        :geometry => "400x400>"
      },
      :large => {
        :geometry => "600x600>"
      },
      :small_download => {
        :geometry => "600x600"
      }
    }
end

      

Here's my paperclip initializer:

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

      

I have four buckets as such:

private.myapp_development
private.myapp_production
public.myapp_development
public.myapp_production

      

The private.xxx stuff shouldn't be public, but the public.xxx buckets should be public.

I can get the app to serve styles that have been marked publicly in public buckets, but I can't seem to make uploads or have a upload action that serves private styles to work.

Here's the log when I try to download:

[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'

      

Here's a log when I try to use my load action for private styles:

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'

      

What am I missing?

rails 3.1.1
paperclip 2.7.0
aws-sdk 1.3.7

      

+3


source to share


1 answer


The paperclip just didn't want to store it in two buckets with the same attachment. So I split the styles into public / private "folders" in the same bucket with different permissions for each style.

Here is my model code:



  has_attached_file :image,
    :storage => :s3,
    :bucket => "myapp-#{Rails.env == 'production' ? 'production' : 'development'}",
    :path => ":bucket/images/galleries/:gallery_id/:id/:style_:id.:extension",
    :url => "/:bucket/images/galleries/:gallery_id/:id/:style_:id.:extension",
    :s3_credentials => { :access_key_id => 'XXXXX', :secret_access_key => 'XXXXXXXXX' },
    :s3_permissions => {
      :thumbnail => :public_read,
      :small => :public_read,
      :medium => :public_read,
      :large => :public_read,
      :small_download => :private,
      :original => :private
    },
    :styles => {
      :thumbnail => {
        :geometry => "80x80>"
      },
      :small => {
        :geometry => "200x200>"
      },
      :medium => {
        :geometry => "400x400>"
      },
      :large => {
        :geometry => "600x600>"
      },
      :small_download => {
        :geometry => "600x600"
      }
    }

      

When I check the file permissions in the s3 console they come up.

0


source







All Articles