I am trying to do the following:
- Select a file on my mobile device in a React Native app using Expo
- Send that file to my PHP (Laravel) server using my application API and the fetch API built into React Native
The file is a .config file in XML format. My code is below:
const XHR = new XMLHttpRequest(),
FD = new FormData();
FD.append('xmldata', this.state.file);
FD.append('meterid', 113);
XHR.addEventListener('load', function(event) {
console.log('SUCCESS');
});
XHR.addEventListener(' error', function(event) {
alert('Error');
});
XHR.onreadystatechange = function () {
console.log(XHR.status);
};
XHR.open('POST', MY_API_URL);
XHR.send(FD);
My code is working on iOS, however I cannot get it working on Android devices. When I run this code on Android it hangs and doesn't give me any response. Does anyone know where I am going wrong here? Thanks in advance.