Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to upload image or pdf file with form-data in react-native?

i found some libraries but i am not sure which one is suitable and stable for me.

i am implementing like email attachment with form-data.

Choose uploading files from gallery or file Manage on Android device and upload to server.

could you recommend nice library? thank you !

what i have found

https://github.com/kaancelen/react-native-nononsense-file-picker

https://github.com/Elyx0/react-native-document-picker

https://github.com/farmisen/react-native-file-uploader

https://github.com/huangzuizui/react-native-file-opener

and so on..

like image 688
jehee choi Avatar asked Oct 16 '25 21:10

jehee choi


1 Answers

You need to first use a document picker - use
react-native-document-picker https://github.com/Elyx0/react-native-document-picker Then create a form data object in callback of document picker

data = new FormData();

data.append('resource', {
    name: res.fileName,
    uri: res.uri, type: res.type
});

var req = {
  method: "POST",
  headers: {
    'Auth-Identifier': access_token,
  },
  body:file
}

use above request in your fetch call. It will work for you.

like image 117
Rishabh Bhardwaj Avatar answered Oct 18 '25 10:10

Rishabh Bhardwaj