PhilipGough
PhilipGough

Reputation: 1779

Cant upload images to s3 bucket with rails app and paperclip

Hi can anyone point me in the direction of what I am doing wrong. I am trying to upload an image to an S3 bucket in EU region, Ireland, using a rails application in development. This is the error I am getting the error

On the following line : TCPSocket.open(conn_address, conn_port, @local_host, @local_port)

I am using the aws-sdk gem and paperclip 4.2.

Here are some code snippets

In:

config/enviroments/development.rb

config.paperclip_defaults = {
  :storage => :s3,
  :s3_host_name => "s3-eu-west-1.amazonaws.com",
  :s3_credentials => {
  :bucket => 'S3_BUCKET_NAME',
  :access_key_id => 'AWS_ACCESS_KEY_ID',
  :secret_access_key => 'AWS_SECRET_ACCESS_KEY'
 }

In

 config/aws.yml
    development:
       AWS_ACCESS_KEY_ID: "xxx"
       AWS_SECRET_ACCESS_KEY: "xxx"
       S3_BUCKET_NAME: "xxx"
       s3_host_name: 's3-eu-west-1.amazonaws.com'

In my model

class Product < ActiveRecord::Base

  validates :avatar,
    attachment_content_type: { content_type: /\Aimage\/.*\Z/ },
    attachment_size: { less_than: 5.megabytes }

  has_attached_file :avatar, styles: {
    thumb: '100x100>',
    square: '200x200#',
    medium: '300x300>'
  }
end

What am I missing? I have looked at every example I could find online and tried to adjust but with no luck.

Thanks

Upvotes: 0

Views: 880

Answers (2)

arunkarottu
arunkarottu

Reputation: 11

Try this:

#config/enviroments/development.rb

config.paperclip_defaults = {
  :storage => :s3,
  :s3_host_name => "s3-eu-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"]
 }

Upvotes: 1

PhilipGough
PhilipGough

Reputation: 1779

Ok, I've solved this by hardcoding the AWS credentials into the development.rb file. So it looks like the problem was the aws.yml file wasn't being loaded, does anyone have any idea why or how to solve this?

Thanks again

Upvotes: 0

Related Questions