Rails 4: Carrierwave/AWS - Excon::Errors::SocketError / getaddrinfo: nodename or servname provided
Posted
技术标签:
【中文标题】Rails 4: Carrierwave/AWS - Excon::Errors::SocketError / getaddrinfo: nodename or servname provided【英文标题】:Rails 4: Carrierwave/AWS - Excon::Errors::SocketError / getaddrinfo: nodename nor servname provided 【发布时间】:2015-02-11 19:00:15 【问题描述】:想使用carrierwave gem 和AWS 从我的应用上传图片。 但是当我上传图片并提交时得到错误
Excon::Errors::SocketError in MoviesController#create
getaddrinfo: nodename nor servname provided
追踪
app/controllers/movies_controller.rb:30:in `block in create'
app/controllers/movies_controller.rb:29:in `create'
Parameters:
"utf8"=>"✓",
"authenticity_token"=>"laitXtzkMnWd/EHtVjFx0X5vE0P4kowXu84wH8fEVOQ=",
"movie"=>"title"=>"new ",
"description"=>"te",
"movie_length"=>"12",
"director"=>"12",
"rating"=>"12",
"image"=>#<ActionDispatch::Http::UploadedFile:0x007fc913845fb0 @tempfile=#<Tempfile:/var/folders/s8/fd5_m1_d3436ptj9znpcy3cc0000gn/T/RackMultipart20150211-642-1ow2dmn>,
@original_filename="IMG_0892.JPG",
@content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"movie[image]\"; filename=\"IMG_0892.JPG\"\r\nContent-Type: image/jpeg\r\n">,
"commit"=>"Create Movie"
MoviesController#create
def create
@movie = Movie.new(movie_params)
respond_to do |format|
**if @movie.save**<--- Error
format.html redirect_to @movie, notice: 'Movie was successfully created.'
format.json render :show, status: :created, location: @movie
else
format.html render :new
format.json render json: @movie.errors, status: :unprocessable_entity
end
但我认为这与我的 aws 设置有关,因为我能够在没有 AWS 的情况下创建图像,但现在由于使用了雾 gem & AWS 访问 & id 键它不起作用
config/initializer.rb
CarrierWave.configure do |config|
config.fog_credentials =
:provider => 'AWS', # required
:aws_access_key_id => 'AKIAIxxxxxxA', # required
:aws_secret_access_key => 'UdRxhdOHoaxxxxxxxx3I9+vIId+',
:region => 'Ireland', # required
config.fog_directory = 'moviesdemo' # required
end
在寻找解决方案后,我相信你现在必须添加区域,但这不起作用。
gemfile
source 'https://rubygems.org'
ruby "2.0.0"
gem 'rails', '4.1.7'
gem 'sqlite3', group: :development
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spring', group: :development
gem 'bootstrap-sass', '~> 3.3.3'
gem 'rails_12factor', group: :production
gem 'pg', group: :production
gem 'carrierwave'
gem 'fog'
image.uploader rb
编码:utf-8
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
# storage :file
storage :fog
【问题讨论】:
【参考方案1】:您的地区应该是“eu-west-1”而不是“Ireland”:
:region => 'eu-west-1',
虽然您应该检查您的存储桶上的区域以确保您选择了正确的。
【讨论】:
对于美国有同样错误的人,认为他们的区域是'us-standard',实际上是'us-east-1'。以上是关于Rails 4: Carrierwave/AWS - Excon::Errors::SocketError / getaddrinfo: nodename or servname provided的主要内容,如果未能解决你的问题,请参考以下文章
rails -v 在安装 4.2.2 后一直说 Rails 3.2.13
在使用 Rails 3 时遇到一些问题,继续使用 Rails 4