Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4, Paperclip, Amazon S3 Config Amazon Path

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 correctly, but the URL that is being returned is incorrect for displaying the upload.

Right now, the url that is being returned is http://s3.amazonaws.com/path/to/my/items (as seen in the picture below).

Instead of s3.amazonaws.com, I would like the root to be specific to the bucket's location (e.g. s3-us-west-1.amazonaws.com/path/to/my/items)

enter image description here

Where should I try and configure a different url path (from s3.amazonaws.com to something else)? I've tried to add a url with the above path into my configuration file like:

  #Paperclip Amazon S3
  config.paperclip_defaults = {
      :storage => :s3,
      :url => "https://s3-us-west-1.amazonaws.com/",
      :s3_credentials => {
          :bucket => ENV['S3_BUCKET_NAME'],
          :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
          :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']

      }

  }

Which did not appear to have any effect. Please advise on where I should be setting this option!

Thanks in advance!

like image 878
meoww- Avatar asked Oct 13 '13 18:10

meoww-


1 Answers

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?

like image 197
Richard Peck Avatar answered Sep 20 '22 02:09

Richard Peck