我在上传图片或文件时使用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请求的形成方式有关,不是吗?
答案 0 :(得分:0)
最后,经过大量研究后,我找到了罪魁祸首。在开发中,我使用Pow服务器运行我的应用程序:http://pow.cx/这在处理文件上传时似乎有间歇性问题。在这个问题上有很多bugs open。
我迁移到Unicorn(这是我在制作中使用的),从那以后一切都很好。