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

我正在使用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);

      });

  };

};


慕标琳琳
浏览 86回答 1
1回答

九州编程

我已经通过评论这一行解决了它 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));     }   });
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript