I am trying to use fetch to upload an image file to my server. Here is my code that I am using:
var formData = new FormData();
formData.append('photo', {uri: './tempImageStore/image.jpg', name: 'photo', type: 'image/jpg'});
and
<Button
onPress={() => fetch('http://localhost:8000/upload', {
method: 'POST',
headers: {
"Accept": "multipart/form-data",
"Content-Type": "multipart/form-data"
},
body: formData
})
}
title={'Upload File'}
/>
However when I run my app and press the Upload File
button, I get an error saying:
I am not sure what I am doing wrong or if this is even the proper way to upload photos to a server.