+ 2
let image = new Image();
// ...
// Convert the image file to a Blob
const file = new File([image], 'image.jpg', { type: 'image/jpeg' });
const blob = new Blob([file], { type: 'application/octet-stream' });
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/octet-stream"
},
body: blob
})
// Note that make sure that the server you are sending the request to is configured to accept octet-stream data.
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
https://developer.mozilla.org/en-US/docs/Web/API/Blob