0

I am trying to do the following:

  1. Select a file on my mobile device in a React Native app using Expo
  2. 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.

1 Answer 1

1

I have managed to solve this by explicitly setting the file type after I select my file. My code to select the file is now the following:

let result = await DocumentPicker.getDocumentAsync({});
result.type = "application/config";

this.setState({
    file: result
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.