mscdex / busboy

A streaming parser for HTML form data for node.js
MIT License
2.86k stars 213 forks source link

with formData() #276

Closed codcodea closed 2 years ago

codcodea commented 2 years ago

Everything works for me when posting from the native < form > element, but I want to post from javascript formData() that is supposed to mimic the native

output. Is it possible?

on formData() https://developer.mozilla.org/en-US/docs/Web/API/FormData

HTTP requests: Native form request OK to the left, and a formData fetch request NOK to the right (same file). https://www.diffchecker.com/93mz4VTV

Error:

21:01:38.768] ERROR: Unexpected end of form

err: {
  "type": "Error",
  "message": "Unexpected end of form",
  "stack":
      Error: Unexpected end of form
          at Multipart._final (/Users/*user*/Documents/JavaScriptProjects/Next/media-server/node_modules/busboy/lib/types/multipart.js:580:17)
          at callFinal (node:internal/streams/writable:694:27)
          at prefinish (node:internal/streams/writable:719:7)
          at finishMaybe (node:internal/streams/writable:729:5)
          at Multipart.Writable.end (node:internal/streams/writable:631:5)
          at IncomingMessage.onend (node:internal/streams/readable:693:10)
          at Object.onceWrapper (node:events:509:28)
          at IncomingMessage.emit (node:events:402:35)
          at endReadableNT (node:internal/streams/readable:1343:12)
          at processTicksAndRejections (node:internal/process/task_queues:83:21)
}

Denied payload:

------WebKitFormBoundarymYp1Tth6Mfb1NinV

Content-Disposition: form-data; name="260231"; filename="webtest19.jpg" Content-Type: image/jpeg

------WebKitFormBoundarymYp1Tth6Mfb1NinV--

mscdex commented 2 years ago

The boundary in the Content-Type header of the request doesn't match that of the boundary used in the payload.

codcodea commented 2 years ago

Thanks for your time! I set the header explicitly to 'Content-Type': 'multipart/form-data; boundary=XXX'. On your input I removed the headers for Content-Type completely to let WebKitFormBoundary do its own thing. Thanks!

Achraffawzi commented 2 years ago

Hi @codcodea , I removed the headers and still getting the same error :'( Any help?

DarthRevanXX commented 2 years ago

same error...