本文介绍了Exconn ::错误:: SocketError文件上载通过Carrierwave与雾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个延续的问题,我最近的 - Stack级别太深的错误 - 具有很强的参数我想生产

每当我做了发布的创作,其中涉及的文件上传,我得到这个错误:

 开始POST/帖为127.0.0.1,在2014年8月28日8时47分○九秒-0500
处理由PostsController#创建为HTML
  参数:{UTF8=&gt;中✓,authenticity_token=&gt;中daUAMfiQZ / UID / 0ADg =,后=&GT; {地位=&gt;中确认,标题=&GT ;艾希莉瘦了10斤5周,照片=&GT;#&LT; ActionDispatch :: HTTP :: UploadedFile的:0x000001038f04b8 @tempfile=#<Tempfile:/var/folders/0f/hgplttnd7dg6q9m62qtbnpn00000gn/T/RackMultipart20140828-89271-qwxck1>, @ original_filename =阿什莉 -  Testimonial.png,@ CONTENT_TYPE =图像/ PNG,@标题=内容处置:表格数据;名称= \后[图] \文件名= \阿什莉 - 见证巴纽\\ r \ nContent类型:图像/ PNG \ r \ N&gt;中的身体=&gt;中,她在5个星期做10PP瘦了10斤},提交=&gt;中提交}
  用户负载(1.0ms的)选择用户。*从用户WHERE用户,ID= 1 ORDER BY用户,IDASC LIMIT 1
   (0.4ms)SELECT COUNT(*)FROM角色INNER JOINusers_rolesON角色,ID=users_roles。ROLE_IDWHEREusers_roles。user_ID的= $ 1 AND(((角色。 NAME ='管理员')和(roles.resource_type IS NULL)AND(roles.resource_id IS NULL)))[user_ID的,1]
   (为0.2ms)BEGIN
  SQL(2.2ms)INSERT INTO上岗(身体,created_at,照片,状态,标题,的updated_at,USER_ID)VALUES($ 1,$ 2,$ 3,$ 4,$ 5 ,$ 6,$ 7)归还ID[[身体,她瘦了10斤5周做10PP。],[created_at,2014年8月28日13:47:09.320765],[照片,阿什莉 -  Testimonial.png],[状态,确认],[标题,艾希莉瘦了10斤5周],[的updated_at,2014年8月28日13 :47:09.320765],[user_ID的,1]
摘要::文摘是德precated;使用摘要
   (0.3ms)ROLLBACK
在10904ms完成500内部服务器错误

EXCON ::错误:: SocketError  - 破碎的管道:
 

我的发表模式是这样的:

 #==架构信息
#
#表名:帖子
#
#ID:整数不为空,主键
#状态:字符串(255)
#标题:字符串(255)
#日期:日期时间
#照片:字符串(255)
#正文:正文
#created_at:日期时间
#的updated_at:日期时间
#USER_ID:整数
#祖先:字符串(255)
#文件:字符串(255)
#

类岗位&LT;的ActiveRecord :: Base的
  has_ancestry
  belongs_to的:用户
  resourcify

  mount_uploader:照片,ImageUploader
  mount_uploader:文件,FileUploader
结束
 

我的控制器看起来是这样的:

 高清创建
    @post = current_user.posts.new(post_params)

    respond_to代码做|格式|
      如果@ post.save
        的format.html {redirect_to时@post,通知:后已成功创建 }
        format.json {渲染:表演,状态:创建,地点:@post}
      其他
        的format.html {渲染:新}
        format.json {渲染JSON:@ post.errors,状态:unprocessable_entity}
      结束
    结束
  结束

  私人
    #从不信任的参数从可怕的网络,只允许白名单通过。
    高清post_params
      params.require(:岗位).permit(:状态:标题:日期:照片,:身体:PARENT_ID)
    结束
 

这是我的 image_uploader.rb

 #编码:UTF-8

类ImageUploader&LT; CarrierWave ::上传::基地
  包括CarrierWave :: RMagick
  存储:雾

  包括CarrierWave :: MIMETYPES
  过程:set_content_type

  高清store_dir
    图像/#{model.id}  - #{model.created_at}
  结束

  版本:拇指做
    过程:resize_to_fit =&GT; [80,80]
  结束

  版本:大做
    过程:resize_to_limit =&GT; [400,400]
  结束

  高清extension_white_list
    %W(JPG JPEG GIF PNG)
  结束

结束
 

这是我的Gemfile:

 来源https://rubygems.org

创业板导轨,4.1.1

组:资产做
  创业板上海社会科学院护栏,GT〜&; 4.0.3
  创业板uglifier','&GT; = 1.3.0'
  创业板咖啡轨,GT〜&; 4.0.0
  宝石字体真棒护栏
  创业板自举 - 萨斯,GT〜&; 3.2.0
  创业板自prefixer护栏
结束

组:发展做
    宝石'注释',github上:CTRAN / annotate_models
    创业板六分仪
  宝石quiet_assets,&GT; = 1.0.2
  创业板better_errors,GT〜&; 1.1.0
  创业板binding_of_caller,GT〜&; 0.7.2
    创业板meta_request
    创业板execjs
    创业板therubyracer
  宝石letter_opener
  宝石'子弹'
  创业板架小型探查
  创业板护栏
  创业板RB-fchange',:要求=&GT;假
  创业板RB-fsevent',:要求=&GT;假
  创业板RB-的inotify',:要求=&GT;假
  创业板后卫livereload,GT〜&; 2.3.0',:要求=&GT;假
  创业板机架livereload','〜&GT; 0.3.15
结束

组:生产做
  创业板rails_12factor
结束

创业板的jQuery护栏
创业板turbolinks
创业板的JBuilder,GT〜&; 2.0
创业板SDOC','〜&GT; 0.4.0,群:DOC
宝石'春天',群:发展
创业板色器件,G​​T〜&; 3.2.4
创业板的薄
创业板PG
创业板cancancan','〜&GT; 1.8.2
创业板rolify
创业板rmagick',:要求=&GT; 'RMagick
宝石mini_magick
创业板carrierwave,GT〜&; 0.10.0
宝石雾,〜&GT; 1.3.1
创业板费加罗,〜&GT; 0.7.0
创业板地理codeR','〜&GT; 1.2.2
创业板社会共享按钮,GT〜&; 0.1.6
宝石'祖先','〜&GT; 2.1.0
宝石simple_form
 

这是我上传的形式部分:

 &LT;%= simple_form_for @post办| F | %&GT;
    &其中;%= f.error_notification%GT;

    &LT;%= f.input:PARENT_ID,如:隐藏%&GT;

    &LT;如果能%? :管理,@post%&GT;
      &LT;%= f.input:现状,收集:Status.all%&GT;
    &LT;%结束%GT;

    &LT;%= f.input:标题%&GT;&LT; BR /&GT;
    &LT;%= f.input:日期%&GT;&LT; BR /&GT;
    &LT;%= f.input:照片%&GT;&LT; BR /&GT;
    &LT;%= f.input:身体%&GT;&LT; BR /&GT;

  &LT;%= f.button:提交%&GT;

&LT;%结束%GT;
 

这是我的配置/ carrierwave.rb 文件:

  CarrierWave.configure办|配置|
  config.fog_credentials = {
    供应商:AWS,
    区域:我们东-1',
    aws_access_key_id:ENV [AWS_ACCESS_KEY],
    aws_secret_access_key:ENV [AWS_SECRET_ACCESS_KEY],
  }
  config.fog_directory = ENV [AWS_MY_BUCKET]
结束
 

任何想法可能会导致什么呢?

更新1

下面是一些更多的调试信息。有一次,我删除图像的大小调整,即插槽错误信息消失。

但是,这是新的错误我得到:

 摘要::精华是去precated;使用摘要
   (为0.2ms)ROLLBACK
在7372ms完成500内部服务器错误

EXCON ::错误::故宫 - 预期(200)LT; =&GT;实际(403禁止)
  请求=&GT; {:connect_timeout =&GT; 60:头=&GT; {内容长度=&GT; 225260,内容类型=&gt;中的图像/ PNG,X-AMZ-ACL=&gt;中公-read,日期=&gt;中星期四,2014年8月28日十六点34分11秒+0000,授权=&gt;中AWS PUBLIC_KEY:SECRET_KEY =,主机=&gt;中my_site.s3。 amazonaws.com:443}:instrumentor_name =&gt;中EXCON:模拟=&GT;假,:​​read_timeout =&GT; 60:RETRY_LIMIT =&GT; 4,:ssl_ca_file =&gt;中。/ RVM /宝石/ ruby-2.1.1@my_site/gems/excon-0.13.4/data/cacert.pem:ssl_verify_peer =&GT;真,:write_timeout =&GT; 60:主机=&gt;中my_site.s3.amazonaws.com :PATH =&gt;中/图片%2F7-2014-08-28 + 16%3A34%3A11 + UTC%2F10pp-主banner.png:端口=&gt;中443:查询=&GT;无,:计划=&gt;中https开头,:身体=&GT;#&LT;文件:/myapp/public/uploads/tmp/1409243651-91536-3147/10pp-main-banner.png> ;,:预计=&GT; 200:幂=&GT;真,:方法=&gt;中PUT}
  响应=&GT; #&LT; EXCON ::回应:0x000001035f0f88 @body =?&LT; XML版本= \1.0 \编码= \UTF-8 \&GT; \ N'LT;错误&GT;&LT; code取代; InvalidAccessKeyId&LT; / code&GT;&LT;消息&gt;您提供的AWS访问密钥ID不存在我们records.</Message><RequestId>2FDE1E67B32981B7</RequestId><HostId>itxnvlzNTkJ29N3MtyYmL8EP29zrW6s9Hr6Xc2P7QzTElkB56OU26WdzsE/6vSz1</HostId><AWSAccessKeyId>AKIAISIFEOAKO3CNPZTA</AWSAccessKeyId></Error>", @headers = {的x AMZ-请求-ID=&gt;中2FDE1E67B32981B7,X-AMZ-ID-2=&gt;中itxnvlzNTkJ29N3MtyYmL8EP29zrW6s9Hr6Xc2P7QzTElkB56OU26WdzsE / 6vSz1,内容类型=&gt;中的应用/ xml的,传输编码=&gt;中的分块,日期=&gt;中星期四,2014年8月28日16时34分十六秒格林尼治标准​​时间,连线=&gt;中关闭,服务器=&GT; AmazonS3},@状态= 403计算值:
 

解决方案

我想它了。当时的情况是我创建了AWS IAM的新用户为这个应用程序,而我没有给用户适当的凭证。即我从来没有创建一个安全策略或将其分配到一组。因此,它是产生一个403错误。

现在,我有固定的,一切工作进展顺利。

我希望这可以帮助别人。

This is a continuation of the problem I recently had - Stack Level Too Deep error - produced with strong parameters I think

Whenever I do a Post creation, which involves a file upload, I get this error:

Started POST "/posts" for 127.0.0.1 at 2014-08-28 08:47:09 -0500
Processing by PostsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"daUAMfiQZ/uiD/0ADg=", "post"=>{"status"=>"confirmed", "title"=>"Ashlee lost 10 pounds in 5 weeks", "photo"=>#<ActionDispatch::Http::UploadedFile:0x000001038f04b8 @tempfile=#<Tempfile:/var/folders/0f/hgplttnd7dg6q9m62qtbnpn00000gn/T/RackMultipart20140828-89271-qwxck1>, @original_filename="Ashlee-Testimonial.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"post[photo]\"; filename=\"Ashlee-Testimonial.png\"\r\nContent-Type: image/png\r\n">, "body"=>"She lost 10 pounds in 5 weeks doing 10PP."}, "commit"=>"Submit"}
  User Load (1.0ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
   (0.4ms)  SELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 1]]
   (0.2ms)  BEGIN
  SQL (2.2ms)  INSERT INTO "posts" ("body", "created_at", "photo", "status", "title", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["body", "She lost 10 pounds in 5 weeks doing 10PP."], ["created_at", "2014-08-28 13:47:09.320765"], ["photo", "Ashlee-Testimonial.png"], ["status", "confirmed"], ["title", "Ashlee lost 10 pounds in 5 weeks"], ["updated_at", "2014-08-28 13:47:09.320765"], ["user_id", 1]]
Digest::Digest is deprecated; use Digest
   (0.3ms)  ROLLBACK
Completed 500 Internal Server Error in 10904ms

Excon::Errors::SocketError - Broken pipe:

My Post model looks like this:

# == Schema Information
#
# Table name: posts
#
#  id         :integer          not null, primary key
#  status     :string(255)
#  title      :string(255)
#  date       :datetime
#  photo      :string(255)
#  body       :text
#  created_at :datetime
#  updated_at :datetime
#  user_id    :integer
#  ancestry   :string(255)
#  file       :string(255)
#

class Post < ActiveRecord::Base
  has_ancestry
  belongs_to :user
  resourcify

  mount_uploader :photo, ImageUploader
  mount_uploader :file, FileUploader
end

My Controller looks like this:

  def create
    @post = current_user.posts.new(post_params)

    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render :show, status: :created, location: @post }
      else
        format.html { render :new }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  private
    # Never trust parameters from the scary internet, only allow the white list through.
    def post_params
      params.require(:post).permit(:status, :title, :date, :photo, :body, :parent_id)
    end

This is my image_uploader.rb:

# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick
  storage :fog

  include CarrierWave::MimeTypes
  process :set_content_type

  def store_dir
    "images/#{model.id}-#{model.created_at}"
  end

  version :thumb do
    process :resize_to_fit => [80, 80]
  end

  version :large do
    process :resize_to_limit => [400, 400]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

end

This is my Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.1.1'

group :assets do
  gem 'sass-rails', '~> 4.0.3'
  gem 'uglifier', '>= 1.3.0'
  gem 'coffee-rails', '~> 4.0.0'
  gem "font-awesome-rails"
  gem 'bootstrap-sass', '~> 3.2.0'
  gem 'autoprefixer-rails'
end

group :development do
    gem 'annotate', github: 'ctran/annotate_models'
    gem 'sextant'
  gem "quiet_assets", ">= 1.0.2"
  gem 'better_errors', '~> 1.1.0'
  gem 'binding_of_caller', '~> 0.7.2'
    gem 'meta_request'
    gem 'execjs'
    gem 'therubyracer'  
  gem "letter_opener"
  gem 'bullet'   
  gem 'rack-mini-profiler'     
  gem 'guard-rails'
  gem 'rb-fchange', :require=>false
  gem 'rb-fsevent', :require=>false
  gem 'rb-inotify', :require=>false
  gem 'guard-livereload', '~> 2.3.0', :require=>false
  gem 'rack-livereload', '~> 0.3.15'
end

group :production do
  gem 'rails_12factor'
end

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'spring',        group: :development
gem 'devise', '~> 3.2.4'
gem 'thin'
gem 'pg'
gem 'cancancan', '~> 1.8.2'
gem 'rolify'
gem 'rmagick', :require => 'RMagick'
gem "mini_magick"
gem 'carrierwave', '~> 0.10.0'
gem "fog", "~> 1.3.1"
gem 'figaro', '~> 0.7.0'
gem 'geocoder', '~> 1.2.2'
gem 'social-share-button', '~> 0.1.6'
gem 'ancestry', '~> 2.1.0'
gem "simple_form"

This is my upload form partial:

<%= simple_form_for @post do |f| %> 
    <%= f.error_notification %>

    <%= f.input :parent_id, as: :hidden %>

    <% if can? :manage, @post %>
      <%= f.input :status, collection: Status.all %>
    <% end %>       

    <%= f.input :title %><br />
    <%= f.input :date %><br />      
    <%= f.input :photo %><br />
    <%= f.input :body %><br />      

  <%= f.button :submit %>

<% end %>

This is my config/carrierwave.rb file:

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider:               'AWS',
    region:                 'us-east-1',                          
    aws_access_key_id:      ENV["AWS_ACCESS_KEY"],         
    aws_secret_access_key:  ENV["AWS_SECRET_ACCESS_KEY"],         
  }
  config.fog_directory  = ENV["AWS_MY_BUCKET"]       
end

Any ideas what may be causing this?

Update 1

Here is some more debugging info. Once I remove the resizing of the images, that Socket Error message disappears.

But this is the new error I get:

Digest::Digest is deprecated; use Digest
   (0.2ms)  ROLLBACK
Completed 500 Internal Server Error in 7372ms

Excon::Errors::Forbidden - Expected(200) <=> Actual(403 Forbidden)
  request => {:connect_timeout=>60, :headers=>{"Content-Length"=>225260, "Content-Type"=>"image/png", "x-amz-acl"=>"public-read", "Date"=>"Thu, 28 Aug 2014 16:34:11 +0000", "Authorization"=>"AWS PUBLIC_KEY:SECRET_KEY=", "Host"=>"my_site.s3.amazonaws.com:443"}, :instrumentor_name=>"excon", :mock=>false, :read_timeout=>60, :retry_limit=>4, :ssl_ca_file=>"/.rvm/gems/ruby-2.1.1@my_site/gems/excon-0.13.4/data/cacert.pem", :ssl_verify_peer=>true, :write_timeout=>60, :host=>"my_site.s3.amazonaws.com", :path=>"/images%2F7-2014-08-28+16%3A34%3A11+UTC%2F10pp-main-banner.png", :port=>"443", :query=>nil, :scheme=>"https", :body=>#<File:/myapp/public/uploads/tmp/1409243651-91536-3147/10pp-main-banner.png>, :expects=>200, :idempotent=>true, :method=>"PUT"}
  response => #<Excon::Response:0x000001035f0f88 @body="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>InvalidAccessKeyId</Code><Message>The AWS Access Key Id you provided does not exist in our records.</Message><RequestId>2FDE1E67B32981B7</RequestId><HostId>itxnvlzNTkJ29N3MtyYmL8EP29zrW6s9Hr6Xc2P7QzTElkB56OU26WdzsE/6vSz1</HostId><AWSAccessKeyId>AKIAISIFEOAKO3CNPZTA</AWSAccessKeyId></Error>", @headers={"x-amz-request-id"=>"2FDE1E67B32981B7", "x-amz-id-2"=>"itxnvlzNTkJ29N3MtyYmL8EP29zrW6s9Hr6Xc2P7QzTElkB56OU26WdzsE/6vSz1", "Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked", "Date"=>"Thu, 28 Aug 2014 16:34:16 GMT", "Connection"=>"close", "Server"=>"AmazonS3"}, @status=403>:
解决方案

I figured it out. What happened was I created a new user in AWS IAM for this app, and I didn't give that user proper credentials. i.e. I never created a security policy or assigned them to a group. So it was generating a 403 error.

Now that I have fixed that, everything works smoothly.

I hope this helps someone else.

这篇关于Exconn ::错误:: SocketError文件上载通过Carrierwave与雾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 09:38