2011-09-19 27 views
12

Jak utworzyć ścieżki za pomocą spinacza do papieru podczas korzystania z usługi Amazon S3?Paperclip i Amazon S3 jak robić ścieżki?

Mój katalog na moim wiadrze jest:

/image/:id/:filename 

Mój model:

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

Odpowiedz

18

Spróbuj tego:

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

napisałem posta o tym kilka miesięcy temu. Pisałem również o tym, jak można dodawać właściwości z klasy, na przykład nie używając identyfikatora (nie podoba mi się to) i zamiast tego używać tokena.

Read the post here...

Podstawy:

aby uzyskać ścieżkę z identyfikatorem

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" 

, a jeśli chcesz go zmienić na coś innego ...

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" 

oraz w inicjalizatorze

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