3

I am trying to send multipart/form-data in an Ajax request. I am using node/busboy to parse the multipart data but it keeps throwing an error

  Error: Multipart: Boundary not found

I have read here that one should pass content-type as undefined and let the browser handle this for you. My problem is that the browser screws this up and sets the contents-type to text/plain instead when it has to be multipart/form-data. The reason for this is busboy only wants to parse multipart/form-data. I want to be able to set the boundaries in away so that busboy can receive the text file. If there is another solution as to how I can send a text file as multipart/form-data so that busboy can parse it I would be open to hear about it.

slipperypete
  • 5,358
  • 17
  • 59
  • 99
  • multipart/form-data has multiple parts, separated by a boundary. The boundary is specified like this: `Content-Type: multipart/form-data; boundary=AaB03x`. So, without a proper content-type, you almost can't have true [multipart/form-data](https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2). – David784 Feb 17 '19 at 03:20

1 Answers1

3

OK so I gave up on this. And then after a week I found out you can do this.

     const form = new FormData();
        headers['Content-Type'] = `multipart/form-data; boundary=${form._boundary}`;
slipperypete
  • 5,358
  • 17
  • 59
  • 99