This is my javascript
function ajax_post(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create
This works as well. Taken from https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
const config = {
headers: {
Authorization: Bearer ${localStorage.token}
,
"Content-Type":
"multipart/form-data; boundary=---------------------------974767299852498929531610575"
}
};
The browser sets the correct headers (including the correct multipart boundary indication in the Content-type) if you haven't manually specified anything.
So all you need to do is remove the following line:
hr.setRequestHeader("Content-type", "multipart/form-data");
Otherwise you will need to set the boundary yourself as it is suggested by Ellias Van Ootegem in Uploading a file with XMLHttprequest - Missing boundary in multipart/form-data:
hr.setRequestHeader("Content-type","multipart/form-data; charset=utf-8; boundary=" + Math.random().toString().substr(2));