问题
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..
回答1:
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.
来源:https://stackoverflow.com/questions/49605686/how-to-upload-image-or-pdf-file-with-form-data-in-react-native