Upload Files to React Native

Asked

Viewed 746 times

-1

Good afternoon, everyone,

I am starting the programming in React-Native and I have a question about using Forms to upload files.

It is possible?

Thank you.

1 answer

0

You must pass the URL of something like Imagepickerou Cameraroll (which should look similar to file://Storage/Emulated/0/Pictures/shj15791-4v61-67g6-z1b6-v8451z956j5k.jpg) to, in formDatathen 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
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.