Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

372
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda