How to set boundaries in an http request?
Asked Answered
D

1

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.

Demonism answered 17/2, 2019 at 2:46 Comment(1)
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.Hilltop
D
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}`;
Demonism answered 20/2, 2019 at 22:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.