Seahorse::Client::NetworkingError Amazon S3 file upload with rails
Well I never found the solution for this problem and had to resort to other options since I was on a deadline. I'm assuming it is a bug on Amazon's end or with the aws-sdk gem, because I have checked my configuration many times, and it is correct.
My workaround was to use the fog gem, which is actually very handy. after adding gem 'fog'
to my gemfile and running bundle install
my code now looks like this:
def upload_to_s3(folder_name)
filename = "ss-" + DateTime.now.strftime("%Y%d%m-%s") + "-" + SecureRandom.hex(4) + ".png"
full_bucket_path = Pathname(folder_name.to_s).join(filename).to_s
image_contents = open(url).read
connection = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => ENV["AWS_ACCESS_KEY_ID"],
:aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"]
})
directory = connection.directories.get(ENV["BUCKET"])
file = directory.files.create(key: full_bucket_path, public: true)
file.body = image_contents
file.save
return file.public_url
end
Which is simple enough and was a breeze to implement. Wish I knew what was messing up with the aws-sdk gem, but for anyone else who has problems, give fog a go.
rails 5 Seahorse::Client::NetworkingError (getaddrinfo: Name or service not known):
Oregon
is not a valid region. It should be us-west-2
, I believe, but check the document linked below to be certain.
I had this exact same problem (resulting in the exact same error message since a getaddrinfo
error is a DNS failure). I was using an invalid region. I was using us-standard
which has been renamed to us-east-1
.
Per the AWS Regions and Endpoints document:
Note
Amazon S3 renamed the US Standard Region to the US East (N. Virginia) Region to be consistent with AWS regional naming conventions. There is no change to the endpoint and you do not need to make any changes to your application.
So, double check the value returned by ENV.fetch('AWS_REGION')
(that which was actually set by heroku config:set AWS_REGION=your_aws_region
, and hope it's not literally your_aws_region
...which I've also done in the past.)
You should be able to check this by running:
heroku get AWS_REGION
Heroku active storage S3 Seahorse::Client::NetworkingError (Net::OpenTimeout)
After deleting config/credentials/production.yml
everything is well.
Ruby rails paperclip Seahorse::Client::NetworkingError (SSL_connect returned=1 errno=0 state=error: certificate verify failed)
Create a file in initializers and place the below code
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
Related Topics
Rails Activerecord: Saving Nested Models Is Rolled Back
Rails 3 - Has_And_Belongs_To_Many
What Is the Ruby Regex for Including Apostrophes
How to Convert a Large Gem to Standalone Rails App
Ruby Project Help. Can't Get Saved Instances from Array
Duplicates in 2 Dimensional Array
How to Make the Say Command Echo a Variable Value in a Script
Adding to the Value in a Hash Table
How to Install Ruby Gems on MAC
Ide Sublime2 How to Find Method Definition
Rails 3 + Daemons Gem: Exception When Querying Model
Ruby: How to Process a CSV File with "Bad Commas"
Rails "Template Is Missing" Error
Make a Ruby Script with Text Io Double Clickable Executable File
How to Properly Create a Associated Record Just After the Associator Record Creation
Knowing When Resque Worker Had Completed Job