Rails 4, Paperclip, Amazon S3 Config Amazon Path

前端 未结 3 434
再見小時候
再見小時候 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:20

    After some experimentation I have found that setting :s3_host_name globally suffices. I ended up with the same problem because I was setting :s3_region, which was being used by Paperclip (post-4.3.1, with aws-sdk 2) for storing attachments, but not when generating the URLs.

    This may also be of interest to readers who end up on this problem: https://github.com/thoughtbot/paperclip/wiki/Restricting-Access-to-Objects-Stored-on-Amazon-S3

    0 讨论(0)
  • 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?

    0 讨论(0)
  • 2021-01-01 02:22

    I also had the same problem when migrating to Spree 2.2 and am still not sure how to solve it the correct way. It seems like Paperclip should have been updating the path from the configuration, but it isn't.

    Lacking a better solution, I've overridden the Spree::Image class like this:

    1 Spree::Image.class_eval do
    2   has_attached_file :attachment, 
    3     styles: { mini: '48x48>', small: '100x100>', product: '240x240>', large: '600x600>' },
    4     default_style: :product,
    5     url: '/spree/products/:id/:style/:basename.:extension',
    6     path: 'products/:id/:style/:basename.:extension',
    7     convert_options: { all: '-strip -auto-orient -colorspace sRGB' }·
    8 end 
    
    0 讨论(0)
提交回复
热议问题