0

在上传图像或文件时,我在使用 Redactor WYSIWYG 编辑器时遇到间歇性错误(澄清一下,它与间歇性使用的文件相同)。

有时上传过程可以正常工作,我在日志中看到了这一点:

Started POST "/redactor_rails/pictures?authenticity_token=GErdxBU0dPRINvw8ZSj6VfBpPQ7hMbwtL0B4YWu94Mg%3D" for 127.0.0.1 at 2013-11-29 12:30:19 +0100
Processing by RedactorRails::PicturesController#create as HTML
  Parameters: {"file"=>#<ActionDispatch::Http::UploadedFile:0x007f8142445258 @original_filename="fish.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"fish.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/kq/6krgq50x6y3dsx4c4mf19f_40000gn/T/RackMultipart20131129-24880-availq>>, "authenticity_token"=>"GErdxBU0dPRINvw8ZSj6VfBpPQ7hMbwtL0B4YWu94Mg="}
  User Load (0.6ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 4 LIMIT 1
   (0.5ms)  BEGIN
  SQL (1.0ms)  INSERT INTO "redactor_assets" ("assetable_id", "assetable_type", "created_at", "data_content_type", "data_file_name", "data_file_size", "height", "type", "updated_at", "user_id", "width") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id"  [["assetable_id", 4], ["assetable_type", "User"], ["created_at", Fri, 29 Nov 2013 06:30:21 EST -05:00], ["data_content_type", "image/jpeg"], ["data_file_name", "fish.jpg"], ["data_file_size", 1961898], ["height", 2448], ["type", "RedactorRails::Picture"], ["updated_at", Fri, 29 Nov 2013 06:30:21 EST -05:00], ["user_id", 4], ["width", 3264]]
   (1.9ms)  COMMIT
  Rendered text template (0.0ms)
Completed 200 OK in 5943ms (Views: 1.0ms | ActiveRecord: 4.0ms)

上传中的其他时间挂起,我在日志中看到了这一点:

Started POST "/redactor_rails/pictures?authenticity_token=GErdxBU0dPRINvw8ZSj6VfBpPQ7hMbwtL0B4YWu94Mg%3D" for 127.0.0.1 at 2013-11-29 12:30:43 +0100
Processing by RedactorRails::PicturesController#create as HTML
  Parameters: {"authenticity_token"=>"GErdxBU0dPRINvw8ZSj6VfBpPQ7hMbwtL0B4YWu94Mg="}
  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 4 LIMIT 1
   (0.2ms)  BEGIN
   (0.2ms)  ROLLBACK
  Rendered text template (0.0ms)
Completed 200 OK in 5ms (Views: 0.4ms | ActiveRecord: 0.9ms)

如您所见,失败的上传操作中的参数中似乎缺少项目。

我似乎得到的唯一错误是在我的浏览器控制台中:Uncaught SyntaxError: Unexpected end of input

对正在发送的实际 HTTP 请求进行了进一步调查,看起来客户端没有正确发送请求中的文件:

成功的 POST 请求:

"rack.request.form_input"=>
<StringIO:0x007ff68cf47f38>, "rack.request.form_hash"=>{"file"=>{:filename=>"fish.jpg", :type=>"image/jpeg", :name=>"file", :tempfile=>
<File:/var/folders/kq/6krgq50x6y3dsx4c4mf19f_40000gn/T/RackMultipart20131129-26808-1jw83tu>, :head=>"Content-Disposition: form-data; name=\"file\"; filename=\"fish.jpg\"\r\nContent-Type: image/jpeg\r\n"}}, "action_dispatch.request_id"=>"db53425e5252ab4045b69e61e076b9d5", "action_dispatch.remote_ip"=>127.0.0.1, "rack.session"=>{"session_id"=>"f5f4102fc79e015efd5abd2ab49156a8", "_csrf_token"=>"Yfvf/glbqZ8RVApod+wFswv84y1sFuiBmtxd9vCG37Q=", "warden.user.user.key"=>["User", [4], "$2a$10$PvP8UOZ27XwZo2fUfQh0H."]}, "rack.session.options"=>{:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false, :secret=>"b929602597766546d091f3312aff29d4eb3057308b332bd3dc97be55a810",...

不成功的 POST 请求:

"rack.request.form_input"=>
<StringIO:0x007ff6905e3ec0>, "action_dispatch.request_id"=>"2c37966c55458361c4246178d353fd67", "action_dispatch.remote_ip"=>127.0.0.1, "rack.session"=>{"session_id"=>"f5f4102fc79e015efd5abd2ab49156a8", "_csrf_token"=>"Yfvf/glbqZ8RVApod+wFswv84y1sFuiBmtxd9vCG37Q=", "warden.user.user.key"=>["User", [4], "$2a$10$PvP8UOZ27XwZo2fUfQh0H."]}, "rack.session.options"=>{:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false, :secret=>"b929602597766546d091f3312aff29d4eb3057308b332bd3dc97be55a810",...

这表明与在客户端形成 HTTP 请求的方式有关,不是吗?

4

1 回答 1

0

最后,经过大量研究,我找到了罪魁祸首。在开发中,我使用 Pow 服务器运行我的应用程序:http: //pow.cx/这在处理文件上传时似乎会出现间歇性问题。在此问题上存在许多错误。

我迁移到了 Unicorn(这是我在生产中使用的),从那以后一切都很好。

于 2013-11-30T10:55:26.667 回答