I'm using Expo and its ImagePicker to grab the image from gallery. It returns both uri
and base64
.
Now I want to upload the image in a multipart/form-data
request.
The problem is that the server only accepts File
while below code sends [object Object]
instead.
const formData = new FormData();
const data = {
jwt,
};
formData.append('message', JSON.stringify(data));
formData.append('avatar', {
uri: avatar,
type: 'image/png',
name: 'avatar.png'
});
fetch(url, {
method: 'POST',
body: formData,
headers: {
Accept: 'application/json',
},
})
Since I'm using Expo I'm limitted to libraries that it supports. Also adding Content-Type
header doesn't work at all and server can't even recognize the message.