简体   繁体   English

Redactor间歇性上载图像和文件

[英]Redactor intermittently uploading images and files

I'm experiencing an intermittent error using the Redactor WYSIWYG editor when uploading images or files (to clarify, it is the same file that it intermittently works with). 上传图片或文件时,我使用Redactor所见即所得(WYSIWYG)编辑器遇到间歇性错误(为澄清起见,它是间歇性使用的同一文件)。

Sometimes the upload process works fine and I see this in the logs: 有时上传过程可以正常运行,我在日志中看到了这一点:

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)

Other times in the upload hangs and I see this in the logs: 上载的其他时间挂起,我在日志中看到了这一点:

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)

As you can see it looks like items are missing from the parameters in the failed upload action. 如您所见,看起来上传失败的参数中缺少项目。

The only error I seem to get is in my browser's console: Uncaught SyntaxError: Unexpected end of input 我似乎得到的唯一错误是在浏览器的控制台中: Uncaught SyntaxError: Unexpected end of input

Did some further investigation into the actual HTTP request that is being sent and it looks like the client isn't correctly sending the file in the request: 对正在发送的实际HTTP请求进行了进一步调查,看起来客户端未正确发送请求中的文件:

A successful POST request: 成功的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",...

An unsuccessful POST request: 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",...

This would suggest is something to do with the way the HTTP request is being formed on the client side, no? 这表明与在客户端形成HTTP请求的方式有关,不是吗?

Finally, after much research I found the culprit. 最后,经过大量研究,我找到了罪魁祸首。 In development I was running my app using the Pow server: http://pow.cx/ This seems to have intermittent problems when dealing with file uploads. 在开发中,我使用Pow服务器运行应用程序: http : //pow.cx/在处理文件上传时,这似乎存在间歇性问题。 There are a number of bugs open on this issue. 在此问题上存在许多错误

I migrated to Unicorn (which is what I use in production) and everything has been fine since. 我迁移到了Unicorn(这是我在生产中使用的),此后一切都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM