想要使用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#创建
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的情况下创建图像,但现在使用了雾宝石&amp; AWS access&amp; id键它不起作用
配置/ initialiser.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
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
答案 0 :(得分:3)
您所在的地区应该是“eu-west-1”而非“爱尔兰”:
:region => 'eu-west-1',
虽然您应该检查您的水桶上的区域,以确保您选择正确的区域。