File Upload via fetch
How can I make file Upload work with react-native-document-picker:
DocumentPicker.show({
filetype: [DocumentPickerUtil.allFiles()],
}, (error, res) => {
const { uri, type: mimeType, fileName } = res;
const formData = new FormData();
formData.append('file', { uri, type: mimeType, name: fileName });
const config = {
method: 'POST',
headers: {Accept: 'application/json'},
body: formData,
};
console.log(config);
return fetch("/endpoint", config).then((response) => { console.log(response); response.json(); });
});
But get back that file is missing in upload on the server
Thanks @mlukasch you save my day.
@mlukasch Thanks this actually works!
@mlukasch How do you send a file with other data ? (like publication date, etc.)
Thank you @schmaluk
@schmaluk you have no IDEA, you basically saved my life !!
This works only for iOS, for Android you get a uri form the ContentProvider of type content:// which FormData can't read