I'm trying to send an http POST request using the JavaScript Fetch API. What I've got so far looks like this (in TypeScript notation):
const fetchHeaders = new Headers();
fetchHeaders.append("Content-Type", "multipart/form-data; boundary=???");
const fetchOptions: RequestInit = {
method: "Post",
body: this.file,
headers: fetchHeaders
}
await fetch("uri", fetchOptions);
Assuming that this.file
is either a .xls
or .xlsx
Excel file uploaded using a <input type="file">
, how do I populate the boundary=
part of the Content-Type
header dynamically when the fetch is called?
When doing this same operation in POSTMAN, the boundary is automatically set and I can't figure out how.