I want to make a post request with form data to send an image like this via fetch API:
function uploadImage(image) {
var data = new FormData();
data.append("upload", image);
fetch('/accounts/upload-image', {
method: 'post',
body: data,
})
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.log(error));
}
But it seems that I missed something? I can not get the data in my server!
Using Postman with no errors it's working So there is something wrong with my fetch function in front end.
The binary data (image) I send to uploadImage(image)
function is like this:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAIQAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAA