使用回形针将文件上载到Amazon S3

时间:2015-12-22 05:14:37

标签: ruby-on-rails ruby amazon-web-services amazon-s3

我正在使用paperclip将文件上传到S3,所以我想知道我是否可以设置类似的路径,

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

问题是:usename来自其他模型;我正在model_2上传文件而:username来自model_1。如何设置路径以指示:username

示例

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

有什么想法吗?

提前致谢!

1 个答案:

答案 0 :(得分:2)

以下是很好的解释:

请查看答案。

Rails 4, Paperclip, Amazon S3 Config Amazon Path

<强>型号:

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

<强>配置/ application.rb中

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

<强>配置/ s3.yml

Amazon AWS Config

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

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

我希望这是你正在寻找的东西:)