Categories
JavaScript Answers

How to fix the fetch Missing boundary in multipart/form-data POST error with JavaScript?

Spread the love

Sometimes, we want to fix the fetch Missing boundary in multipart/form-data POST error with JavaScript.

In this article, we’ll look at how to fix the fetch Missing boundary in multipart/form-data POST error with JavaScript.

How to fix the fetch Missing boundary in multipart/form-data POST error with JavaScript?

To fix the fetch Missing boundary in multipart/form-data POST error with JavaScript, we set the Accept request header to "*/*" to accept all response MIME types.

For instance, we write

const options = {
  //...
  headers: new HttpHeaders({
    Accept: "*/*",
    Authorization:
      "Bearer " + JSON.parse(sessionStorage.getItem("token")).token,
    "Access-Control-Allow-Origin": this.apiURL,
    "Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, PATCH, DELETE",
    "Access-Control-Allow-Headers":
      "origin,X-Requested-With,content-type,accept",
    "Access-Control-Allow-Credentials": "true",
  }),
  //...
};
await fetch(url, options);

to create a HttpHeaders object with the Accept header set to "*/*" to set "*/*" as the Accept request header value.

Then we call fetch with the options object to make a request to the url with all the request headers listed.

Conclusion

To fix the fetch Missing boundary in multipart/form-data POST error with JavaScript, we set the Accept request header to "*/*" to accept all response MIME types.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *