我正在使用paperclip
将文件上传到S3,所以我想知道我是否可以设置类似的路径,
:path => "/advertisements/:username/:filename”
问题是:usename
来自其他模型;我正在model_2
上传文件而:username
来自model_1
。如何设置路径以指示:username
示例:
:path => "/advertisements/@model_1.username/:filename”
有什么想法吗?
提前致谢!
答案 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 强>
development:
access_key_id: **********
secret_access_key: **************
bucket: ****
production:
access_key_id: ***********
secret_access_key: ***********
bucket: ****
我希望这是你正在寻找的东西:)