I recently encountered a problem with the document upload feature in Expo CLI - React Native. The issue is that the file is not being transmitted to the backend as expected using FormData(); instead, it is arriving in a strange array format that is different from how it works on the website. I have the same endpoint connected to a React JS project and it functions properly, delivering the documents correctly in the browser.
However, I am not sure what is causing the issue with FormData here. I also attempted to use react-native-fs, but it is not compatible with Expo. Below is my code:
let formData = new FormData();
formData.append('file', doc);
let token = this.props.user.token;
let header = { headers: { 'Accept': '*', 'Authorization': 'Bearer '+token, 'Content-Type': 'multipart/form-data' } };
let res = await axios.post(BackendURL+'/porta/files/upload/'+document.projectDocumentId, formData, header);
if(res.data.success === true){
alert('File uploaded successfully');
this.props.ReloadData(true);
}
console.log(doc);