Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6215

axios post request in react native and react app with JSON Stringify and blob

$
0
0

I am making an app in which I am calling an API end point in react native but I am getting this error but in the web app (its done with react) it doesn't show any error, Here is the web app code in react with typescript

 try {        let result: any;        const criteriaWithNoFile = {            content: filterCriteria.content ? filterCriteria.content.trim() : '',            filterLimit: filterCriteria.filterLimit,            sorting: filterCriteria.sorting,            contractionOption: filterCriteria.contractionOption,            contentId: filterCriteria.contentId,            url: filterCriteria.url ? filterCriteria.url.trim() : ''        }        if (localStorage.getItem('currentUserToken')) {            dispatch({                type: LOADER,                payload: true            });            const formData = new FormData();            const jsonFilterCriteria = JSON.stringify(criteriaWithNoFile);            const blobFilterCriteria = new Blob([jsonFilterCriteria], {                type: 'application/json'            });            formData.append("filterData", blobFilterCriteria);            formData.append("filterFile", filterCriteria.selectedFile);            console.log('FormData', formData);            try {                result = await authAxios.post(`${process.env.REACT_APP_BASE_URL}/filter`, formData, {                    headers: {'Content-Type': 'multipart/mixed'                    }                });

and here is the code I am trying in react native

const filterData = {  content: '',  filterLimit: 1000,  sorting: 'NATURAL',  contractionOption: 'LEAVE_CONTRACTION',  contentId: '',  url:'https://stackoverflow.com/questions/37552973/get-the-time-zone-with-react-native',};const data = new FormData();const jsonFilter = JSON.stringify(filterData);const blobFilter = new Blob([jsonFilter], {  type: 'application/json',});data.append('filterData', jsonFilter);data.append('filterFile', selectedFile);await axios  .post('https://capi.beebl.io/filter', data , {    headers: {'Content-Type': 'multipart/mixed',    },  })  .then((res) => console.log(res))  .catch((err) => console.log(err));

Can anyone help me what I am doing wrong....


Viewing all articles
Browse latest Browse all 6215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>