We are building a photo upload feature in our application, which is built using react native.
I am using this: https://github.com/marcshilling/react-native-image-picker
Upon selecting the image, I get the URI of the image, something like this: file:///storage/151A-3C1B/Pictures/image-c47d8624-8530-43df-873e-e31c2d27d0e9.jpg
I can also get the base64 encoded string of the image, but I do not want to deal with base64, since it slows down the app and the result is about 1/3 bigger request.
So my question is, I have the URI like above, how can I send the contents of the file to my API backend? It expects multipart/form-data, the name "photo".
I wanted to try with this:
var formData = new FormData();
formData.append('photo', CONTENTS);
But I do not know how to get the contents of the file, or how to pass the file URI to the formData object, so the contents would be sent, not the URI string itself. Any help please?