Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
React native, write xml string to .xml file and send it to server

I'm trying to send xml string as a .xml file to server, as I able to create .xml file and wrote data in it with the help of react-native-fs but I unable to send it to api. I think it's not picking up the path. can anyone tell me how to properly do that.

Here is my code

const getToken = async () => {
    updateState({isLoading: false});
    const xml = await onJsonToXmal();

    //create path for that xml file
    const path = RNFS.DocumentDirectoryPath + '/test.xml';

    // write xml into that file
    RNFS.writeFile(path, xml, 'utf8')
      .then((success: any) => {
        // console.log(success, 'success');
      })
      .catch((err: any) => {
        // console.log(err.message);
      });

    const checksum = md5(xml);

    const formData = new FormData();
    formData.append('file', {
      uri: path,
      type: 'xml',
      name: 'demo.xml',
    });
    // formData.append('checksum', checksum);

    axios({
      method: 'post',
      url: 'some url',
      headers: {
        'Content-Type': 'multipart/form-data',
        Authorization:
          'Bearer some token',
      },
      data: {
        file: formData,
        checksum,
      },
    })
      .then(res => {
        console.log(res.data);
        updateState({isLoading: false});
      })
      .catch(error => {
        console.log(error);
        Alert.alert(`${error}`);
        updateState({isLoading: false});
      });
  };

  const onJsonToXmal = () => {
    const data = dummyData; //dataForXml
    const res = toXML(data);
    return res;
  };

thank you

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!