2012-03-16 8 views
3

私は、多くのスタイルに加工されたクリップクリップ付きのGalleryPhotoモデルを持っています。一部のスタイルは一般に閲覧可能である必要があります。いくつかはプライベートである必要があります。さまざまな許可で異なるスタイルを切り取る

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

private.xxxバケットはすべきではない:私はのような4つのバケツを持って

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 

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 

はここに私のクリップ初期化子です:ここで

は私のモデルですpublic.xxxバケットは公開されていなければなりません。

パブリックバケットで公開されているスタイルに対応するためのアプリを手に入れることはできますが、私はアップロードを行うことはできません。私は何をしないのです

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' 

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

ここで私はプライベートスタイルのための私のダウンロードアクションを使用しようとするログがあります:私は、アップロードをしようとするとき

はここにログですか?

rails 3.1.1 
paperclip 2.7.0 
aws-sdk 1.3.7 
+0

ラムダはあなたのために機能しますか?これを見てくださいhttp://stackoverflow.com/questions/8590822/apply-processor-with-paperclip-if-condition-its-true – mohamagdy

+0

あなたの新しいファイルのアクセス権に問題がありますか? BucketOwnerFullControlオプションを設定する必要がありますか? [例えば、](http://stackoverflow.com/questions/7616810/amazon-s3-upload-with-public-permissions) –

答えて

0

ペーパークリップは、同じ添付ファイルを持つ2つのバケットに保存したくないだけです。だから私は同じスタイルのパブリック/プライベート "フォルダ"にスタイルを分けていました。

ここに私のモデルのコードは次のとおりです。

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" 
     } 
    } 

私はS3コンソールでファイルのパーミッションをチェックすると、彼らが適切です。

関連する問題