我正在使用react-native-image-crop-picker從畫廊獲取圖像并嘗試使用 Axios 將其上傳到服務器上。但它沒有上傳到服務器,當我點擊 api 上傳時它開始發送并且永無止境并且沒有從服務器獲得響應。但是當我嘗試構建它然后嘗試上傳然后它成功上傳并從服務器獲得響應時。這是我的代碼。const handleProfilePic = () => { const date = new Date(); const formData = new FormData(); formData.append('files', { uri: image.path, type: image.mime, name: 'image_' + Math.floor(date.getTime() + date.getSeconds() / 2), }); console.log(formData); new Promise((rsl, rej) => { setLoading(true); updatePic(formData, user.auth, rsl, rej); }) .then((res) => { Snackbar.show({ text: res, duration: Snackbar.LENGTH_SHORT, }); setLoading(false); }) .catch((errorData) => { setLoading(false); Snackbar.show({ text: errorData, duration: Snackbar.LENGTH_SHORT, }); }); };//add pic code export const updatePic = (data, token, rsl, rej) => { return (dispatch) => { axios(`${BASE_URL}/Authentication/addpicture`, { method: 'post', data, headers: { auth: token, }, }) .then((res) => { console.log(res); if (res.data.status == true) { rsl(res.data.message); } else { rej(res.data.message); } }) .catch((err) => { console.log(err); rej(err.message); }); };};
在調試模式下,圖像和視頻未使用 axios 上傳到服務器
慕標琳琳
2023-06-09 15:26:10