Currently, I am utilizing ajax (jquery) to POST image data in the following manner. The image
being used is a File
object.
async function postImage({ image }) {
const result = await $.ajax({
method: 'POST',
url: '/api/images',
dataType: 'json',
data: image,
processData: false,
async: true,
headers: {
'Content-Type': 'application/octet-stream',
},
});
return result;
}
The returned object contains the ID of the image and is structured as {id: imageID}
.
I am now looking for guidance on how to achieve the same functionality using the Fetch API
. Despite attempting the following code snippet, I have been unsuccessful in getting the desired result
.
const result = await fetch('/api/images', {
method: 'POST',
body: image,
headers: {
'Content-Type': 'application/octet-stream',
},
});
return result;