2011-09-19 20 views
12

Amazon S3 kullanırken kağıt ataçlı yolları nasıl oluşturabilirim? Benim kova üzerinePaperclip ve Amazon S3 yolları nasıl?

Benim dizinidir:

/image/:id/:filename 

Benim modelim:

has_attached_file :image, 
    :storage => :s3, 
    :bucket => 'mybucket', 
    :s3_credentials => { 
     :access_key_id => ENV['S3_KEY'], 
     :secret_access_key => ENV['S3_SECRET'] 
    } 

cevap

18

bu deneyin:

has_attached_file :image, 
    :storage => :s3, 
    :bucket => 'mybucket', 
    :path => "/image/:id/:filename", 
    :s3_credentials => { 
     :access_key_id => ENV['S3_KEY'], 
     :secret_access_key => ENV['S3_SECRET'] 
    } 
10

Birkaç ay geri bu konuda bir yazı yazdı. Ayrıca sınıftaki özellikleri nasıl ekleyebileceğinizi yazdım, örneğin bir kimlik kullanmıyorum (beğenmedim) ve bunun yerine bir belirteç kullanıyorum.

Read the post here...

temelleri: Başka bir şeyle değiştirmek isterseniz

, bir kimlik

has_attached_file :avatar, 
  :styles => 
  { 
    :tiny => "48x48>", 
    :preview => "175x175>", 
    :large => "300x300>", 
    :huge => "500x500>" 
  }, 
  :storage => :s3, 
  :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", 
  :path => ":class/:attachment/:id/:style.:extension", 
  :bucket => 'lopsum', 
  :default_url => "/images/photo01.jpg" 

içeren bir yol almak ve ...

has_attached_file :avatar, 
  :styles => 
  { 
    :tiny => "48x48>", 
    :preview => "175x175>", 
    :large => "300x300>", 
    :huge => "500x500>" 
  }, 
  :storage => :s3, 
  :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", 
  :path => ":class/:attachment/:token/:style.:extension", 
  :bucket => 'lopsum', 
  :default_url => "/images/photo01.jpg" 

ve bir başlatıcıda

Paperclip.interpolates :token do |attachment, style| 
  attachment.instance.token 
end