为了账号安全,请及时绑定邮箱和手机立即绑定

在调试模式下,图像和视频未使用 axios 上传到服务器

在调试模式下,图像和视频未使用 axios 上传到服务器

慕标琳琳 2023-06-09 15:26:10
我正在使用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);      });  };};
查看完整描述

1 回答

?
九州编程

TA贡献1785条经验 获得超4个赞

我已经通过评论这一行解决了它 Open this dir 'android/app/src/debug/java/com/flatApp/ReactNativeFlipper.java'


NetworkingModule.setCustomClientBuilder(

   new NetworkingModule.CustomClientBuilder() {

     @Override

     public void apply(OkHttpClient.Builder builder) {

       // builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));

     }

   });


查看完整回答
反对 回复 2023-06-09
  • 1 回答
  • 0 关注
  • 81 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信