store images locally for development s3 for production Rails Paperclip

前端 未结 3 1125
花落未央
花落未央 2021-02-18 15:24

I want to upload images on my local machine for development but store them on my Amazon S3 account for production.

upload.rb

if Rails.env.development?
           


        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-18 15:47

    Sure. Try something like this:

    paperclip_opts = {
      :styles => { :thumb => '40x40#', :medium => '150x200>', :large => '300x300>' },
      :convert_options => { :all => '-quality 92' },
      :processor       => [ :cropper ]
    }
    
    unless Rails.env.development?
      paperclip_opts.merge! :storage        => :s3,
                            :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
                            :path           => ':attachment/:id/:style.:extension',
                            :bucket         => 'birthdaywall_uploads',
    end
    
    has_attached_file :photo, paperclip_opts
    

    In addition to the obvious unless/merge! block, also note the use of :all for :convert_options instead of specifying an identical option three times.

提交回复
热议问题