The image data which is requested by the API is multipart form data but i am just providing the image data to it.i want to convert the image data to FormData.
Use FormData
You'll need to use the append
method on it to add the image.
Here's some sample code:
const formData = new FormData();
formData.append('nameOfTheKeyYouWantToSetThisDataTo', myFileInput.files[0], 'avatar.jpg');
You can then send the data to your API using the fetch
API.
fetch(url, {
method: 'POST',
body: formData
}).then(function (response) {
...
});