ruby PaperClip + S3带有自定义路径

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby PaperClip + S3带有自定义路径相关的知识,希望对你有一定的参考价值。

#config/initializers/paperclip.rb

Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-west-2.amazonaws.com'
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename.#{Time.now.to_i}'
#config/environments/production.rb

config.paperclip_defaults = {
  :storage => :s3,
  :s3_credentials => {
    :bucket => ENV['S3_BUCKET_NAME'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }
}
class SomeModel < ActiveRecord::Base 
  
  has_attached_file :avatar, styles: {
    thumb: '100x100>',
    square: '200x200#',
    medium: '300x300>'
  }
 
  validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end

以上是关于ruby PaperClip + S3带有自定义路径的主要内容,如果未能解决你的问题,请参考以下文章

如何显示来自 S3/Paperclip/Heroku 的图像?

将 Paperclip 数据库迁移到 Active Storage Amazon S3

Paperclip S3 - 可以上传图像但无法查看它们

上传图片 - Nodejs Paperclip 和 S3

Rails 6,Paperclip,S3,s3_direct_upload @attachment.save 在 s3_direct_upload 完成后不保存

ruby Paperclip中的协议相对URL