Search code examples
javascriptnode.jskoabusboy

How to set boundaries in an http request?


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.


Solution

  • 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}`;