From past few days I am trying to send formData using axios / fetch with required headers but the response is network error.
Could anyone please share a code snippet on how to make it work in react native.
Thanks,
code as follows:
var formdata = new FormData();
var file = new File([base64Data], "ISDD_" + this.state.fileName, { lastModified: new Date().getMilliseconds() })
formdata.append("file", file, this.state.fileName);
formdata.append("folderName", this.state.folderName);
formdata.append("userName", "[email protected]");
formdata.append("documents", documents);
axios({
url: url,
method: 'POST',
headers: {
// "Content-Type": 'multipart/form-data',
'enctype': 'multipart/form-data',
'Cache-Control': 'sno-cache',
'Pragma': 'no-cache'
},
data: formdata
})
.then((response) => {
console.log(`1 ${response}`)
})
.catch((error) => {
console.log(error)
})
formdata
should be a FormData object. You should declare it before to append data to it:const formdata = new FormData(); formdata.append(...)
– SylvainF