How can i upload file to server using react-native's fetch api Need to achieve something similar to this-
------WebKitFormBoundaryRAxza9ew2ADaYHn5
Content-Disposition: form-data; name="file"; filename="66154520.jpg"
Content-Type: image/jpeg
------WebKitFormBoundaryRAxza9ew2ADaYHn5--
You didn't show any kind of code, but in theory...
You should pass url from something like ImagePicker
or CameraRoll
(which should look similar to file:///storage/emulated/0/Pictures/shj15791-4v61-67g6-z1b6-v8451z956j5k.jpg
) to formData
and then pass it along with the request:
const form = new FormData();
form.append('image', {
uri: "file:///...",
type: 'image/jpg',
name: 'image.jpg',
});
fetch('https://example.com/api/upload', {
method: 'POST',
body: form
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With