I tried to upload a file using axios in react-native and on the web using the following sample code
const obj = {
hello: "world"
};
const json = JSON.stringify(obj);
const blob = new Blob([json], {
type: 'application/json'
});
const data = new FormData();
data.append("document", blob);
axios({
url: 'SOME_URL',
method: 'POST',
headers:{...}
},
data: data
})
.then(res => console.log(res))
.catch(res => console.log(res))
On react-native it is setting the content-type as "text/plain" but when I tried on the web it is setting the correct content-type as "multipart/form-data".
I tried setting Content-Type : 'multipart/form-data' but still it reverts back to text/plain in react-native.
I did follow this link sending file and json in POST multipart/form-data request with axios but it didn't work on react-native
Can anyone help on how to upload a file and a json along with it in react-native ?
Aucun commentaire:
Enregistrer un commentaire