简体   繁体   中英

File upload to Amazon S3 using paperclip

I'm uploading files to S3 using paperclip so would like to know if i can set the path something like,

:path => "/advertisements/:username/:filename”

the thing is that :usename is from other model; i'm uploading files on model_2 and :username comes from model_1 . How can i set the path to indicate the :username

Sample :

:path => "/advertisements/@model_1.username/:filename”

Any ideas?

Thanks in advance!

Here is nice explanation:

please view the answer.

Rails 4, Paperclip, Amazon S3 Config Amazon Path

Model:

#Image Upload 
Paperclip.options[:command_path] = 'C:\RailsInstaller\ImageMagick'
has_attached_file :image,
        :styles => { :medium => "x300", :thumb => "x100" },
        :default_url => "****",
        :storage => :s3,
        :bucket => '****',
        :s3_credentials => S3_CREDENTIALS,
            :url => "/:image/:id/:style/:basename.:extension",
            :path => ":image/:id/:style/:basename.:extension"

config/application.rb

# Paperclip (for Amazon) (we use EU servers)
  config.paperclip_defaults = {
    :storage => :s3,
    :s3_host_name => 's3-eu-west-1.amazonaws.com'
  }

config/s3.yml

Amazon AWS Config

development:
  access_key_id: **********
  secret_access_key: **************
  bucket: ****

production:
  access_key_id: ***********
  secret_access_key: ***********
  bucket: ****

I hope this is what you're looking for :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM