简体   繁体   中英

Multipart file upload issue

I have a Koa application that has a multipart/form-data file upload that has suddenly stopped working. I have spent over 8 hours now trying to isolate the issue. What I've tried/verified:

  • Not a Node 6 issue; same problem occurs with Node 4 (which was previously working).
  • Have ruled out version issues in packages.json ; have tested against originally working versions of all relevant packages, and latest versions.
  • Issue exhibits in latest Chrome and latest Firefox.
  • Issue does NOT exhibit when POSTing directly from Postman with exact same headers as browser is sending (excepting Cookie and Referer , neither of which can be set in Postman).
  • Problem exhibits with Koa wrappers koa-better-body and koa-multer .
  • Problem exhibits when directly using busboy , formidable , and even multiparty .
  • Similar to problems people were reporitng on this multer issue ; tried all suggestions (including the long shot of adding field parameters before file parameter) to no avail.
  • Have tried to recreate minimal test case to reproduce, but have been unable to.
  • Have tried whittling down my app line by line, examining Babel output against minimal test case until they are functionally identical, problem still persists in my app, but not in test case.
  • All tests running on the same server, with the same browsers.

When debugging, the cleanest view of the problem is with formidable, in incoming_form.js . A single data event occurs:

在此输入图像描述

Then an abort event:

在此输入图像描述

After that, the browser eventually times out. (The file is larger than the 15 bytes being received in the first data event.)

I had hoped for a quick fix by switching from formidabl to busboy, and now I am a real bind, because this problem needs to get fixed, and I am running out of ways to look at the problem. I've tried to slice it every way I can think of, debug it every way I can think of, and short of writing my own multipart parser (not a task I would relish), I'm fast running out of options.

Has anyone run across this? Do you have any ideas how I might proceed with debugging or producing a minimum test case?

It turns out the issue was with koa-proxy : it doesn't correctly forward multipart POST requests. I fixed it by switching to koa-proxy2 , and I will look into contributing a fix to the koa-proxy project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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