In the following snippet downloading works as expected but uploading is not working, getting a HTTP 500 response. The issue isn't backend as it works in Postman or equivalent.
What could be the issue?
return fetch('url', {
method: 'GET',
}).then((response) => {
//upload
if (response.status === 200) {
let blob = response.blob();
return fetch('url', {
method: 'POST',
headers: {
'Content-Type': 'application/octet-stream',
},
body: blob,
}).then((response) => {
console.log(response.status);
});
}
});
Try using form data,
if (response.status === 200) {
let blob = response.blob();
const formData = new FormData();
formData.set('file', blob);
return fetch('url', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data'
},
body: blob,
}).then((response) => {
console.log(response.status);
});
}