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