Uploading Files in React Native

0

Good afternoon guys,

I'm starting programming in react-native and I'm having a question about using forms to upload files.

Is it possible?

Thank you.

    
asked by anonymous 01.09.2018 / 18:09

1 answer

0

You should pass the URL of something like ImagePicker or CameraRoll (which should look similar to file: ///storage/emulated/0/Pictures/shj15791-4v61-67g6-z1b6-v8451z956j5k.jpg), in formDatfollow, pass it together 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
});
    
05.09.2018 / 16:08