Rails 4, Paperclip, Amazon S3 Config Amazon Path

前端 未结 3 450
再見小時候
再見小時候 2021-01-01 01:57

I\'m trying to configure the endpoint which is returned from paperclip when my object is successfully uploaded to Amazon\'s S3 service. The upload and everything is working

3条回答
  •  耶瑟儿~
    2021-01-01 02:21

    If you're going to use S3, we've found that you have to include the S3 credentials in your actual model (not just the config files). Here's what we do:

    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: ****
    

    Hope this helps?

提交回复
热议问题