carrierwave + amazon s3 socket error - ruby-on-rails

My problem is really similar to this one:
rails + carrierwave + fog + S3 socket error
I was experimenting with regions but without a luck.
I'm trying to use carrierwave + fog + amazon s3 as described on wiki and in few similar questions here on stackoverflow. So, here are my files:
config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.fog_directory = 'folder_name_here' # my bucket name
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'access_key_here', # copied from amazon
:aws_secret_access_key => 'secret_key_here', # copied from amazon
:region => 'eu-west-1' # my bucket has region set to Ireland
}
end
My uploader has a storage parameter set to :fog.
And now, when i'll try to save my model, i'm getting the following error:
getaddrinfo: Name or service not known (SocketError)
Have you any idea what am i possibly doing wrong? If any further info is needed, please just let me know.

Did you restart your server when adding in the carrierwave and fog gem?

Related

Upload files to amazon aws3 rails with carrierwave error hostname does not match the server certificate

I followed this tutorial:
http://lifesforlearning.com/uploading-images-with-carrierwave-to-s3-on-rails/
I had working carrierwave uploader which was storing files to disk space
What I did step by step:
1)added fog gem and run bundle install and bundle update
2)in config/initializers I created r3.rb file with this:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'mykey',
:aws_secret_access_key => 'mysecretkey',
:region => 'us-west-2' # Change this for different AWS region.
}
config.fog_directory = "bucket-main"
end
I ran rails s and tried to save some photo. But as you can see on the picture my bucket is empty.So they must be stored to my disk.
What do I do now?
Update I changed storage to fog.
Here is my photouploader class code:
# encoding: utf-8
class PhotoUploader < CarrierWave::Uploader::Base
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
And now I get this error:
hostname "bucket-main.bucket-main.s3-us-west-1.amazonaws.com" does not
match the server certificate (OpenSSL::SSL::SSLError)
i eventually solved my problem by updating
bundle update fog
and
bundle update carrierwave
Try adding path_style to your config and the fog_directory
config.fog_credentials = {
...
:path_style => true
}
config.fog_directory = 'bucket-main'
I just spent a few hours tracking down the cause of this error, which I was also getting:
hostname "bucket-main.bucket-main.s3-us-west-1.amazonaws.com" does not match the server certificate (OpenSSL::SSL::SSLError)
The odd thing is how the bucket name is repeated twice in the hostname. It turned out I had configured the wrong region name. Notice in your config.fog_credentials you have
:region => 'us-west-2'
...but the hostname in the exception has s3-us-west-1? If your bucket is in one AWS region, but you configure a different region in your Fog credentials, Fog will try to follow a redirect from AWS, and somehow the bucket name gets doubled up in this situation. Fog produces a warning about the redirect, but Carrierwave ends up hiding this from you.
Set :region in your Fog credentials to where the bucket actually is in AWS, and the does not match the server certificate exception will stop happening.

Store file to amazon s3 rails?

I have a working heroku app. But since heroku doesn't provide persistent file storage, I'd like to use amazon s3.
I found heroku tutorial https://devcenter.heroku.com/articles/s3
But it seems confusing to me and may be a little bit complicated.
Right now I use carrierwave gem for storing files.
So may be you can give me a small and simple example of code u use to store files to amazon file storage?
UPDATE:
I found this code(is it that simple just a few lines in carrierwave, add gem called fog and that's all? or will I need something else?):
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => "YOUR AMAZON ACCESS KEY",
:aws_secret_access_key => "YOUR AMAZON SECRET KEY",
:region => 'us-west-1' # Change this for different AWS region. Default is 'us-east-1'
}
config.fog_directory = "bucket-name"
end

Fog issue using iam profile and fetching urls from aws

Using Fog w/ AWS instance profiles and after 3 day my s3 urls are no longer working. I'm getting fresh urls, but the error returned from AWS is The provided token has expired. Restarting the application gets everything working again, but no errors other than the one from AWS are present.
I have read that switching to keys should fix my issue, but I was hoping to keep my iam profile. Has anyone run into this?
my Carrierwave config is bellow and I am using Carrierwave version 0.9.0 and Fog 1.28.0
CarrierWave.configure do |config|
fog_credentials = {
:provider => 'AWS',
:region => 'us-east-1',
:path_style => true,
:host => 's3-external-1.amazonaws.com' # routes all requests to Northern Virginia datacenter
}
if defined?(Settings.use_iam_profile) && Settings.use_iam_profile
fog_credentials[:use_iam_profile] = true
else
fog_credentials[:aws_access_key_id] = Settings.s3_access_key
fog_credentials[:aws_secret_access_key] = Settings.s3_secret_key
end
config.fog_credentials = fog_credentials
config.fog_directory = Settings.s3_bucket_name # required
config.fog_public = false # optional, defaults to true
config.root = File.join(Rails.root, 'private')
end
So this link got updated, basically the issue was While the signing token was being refreshed correctly when downloading files with fog, it wasn't being refreshed when signing an S3 URL.
There was a pull request made on fog to fix this issue

Carrierwave / Fog / S3 "is not a recognized storage provider"

I have a Rails app that is using Carrierwave for file uploads. It has been working fine but I want to start using Amazon S3 for my image storage. I am getting this error:
ArgumentError ( is not a recognized storage provider):
app/controllers/salons_controller.rb:52:in `update'
I have made sure I have the latest gems for Carrierwave and Fog. This is in my Gemfile:
gem 'carrierwave'
gem 'aws-sdk'
gem 'fog'
fog.rb looks like:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'MYACCESSKEY',
:aws_secret_access_key => 'MYSECRETKACCESSKEY',
:region => 'us-east-1'
}
config.fog_directory = 'andrunix'
config.fog_public = true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
The Uploader class looks like:
class SalonImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :fog
def store_dir
# "andrunix" is the bucket name on S3
"andrunix/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
If I change the storage back to 'file', it works fine. Setting storage to 'fog' generates this error.
OK, I'm an idiot. :)
At some point, I don't know where, I added a fog.rb file with my CarrierWave configuration to the lib/carrierwave/storage directory. I got desperate, paid for a Railscasts subscription so I could watch episode #383 (http://railscasts.com/episodes/383-uploading-to-amazon-s3?autoplay=true) and at 3:02 I found the error of my ways. The Carrierwave configuration needed to be placed in config/initializers/carrierwave.rb.
I don't know where I got this other location but once I moved the config to the proper location, everything is good.
I just ran into the same problem, and people must be aware that any typo in the config file : "config/initializers/carrierwave.rb", leads to that error.

Carrierwave + Fog Error "Errno::EACCES in ProjectsController#update"

I am using carrierwave with fog to store images on amazon's s3. I've followed all the guides, but i keep getting the same basic error and it seems incorrectly.
Errno::EACCES in ProjectsController#update
Permission denied - C:/rails-projects/myrailsapp/tmp/20111203-2006-7864-6681/jolly-rows.jpg
however, the uploaded image is still being placed in the cached dir and it's being uploaded to the amazon s3 server.... so why is it throwing this error?
i have
CarrierWave.configure do |config|
config.root = Rails.root.join('tmp')
config.cache_dir = 'carrierwave'
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'SECRET',
:aws_secret_access_key => 'SECRET'
}
config.permissions = 0777
config.fog_directory = 'ia_test_dir'
config.fog_public = true
end
in an initializer. please help...thanks!
Update: still haven't been able to get this to work. I've a few other things, like changing the tmp dir, not setting the tmp, etc.. and nothing please help. anyone?
Is there something my question is missing that's keeping people from responding?

Resources