Images and Videos are not uploading to server using axios while in debugging mode

163 views Asked by At

I'm using react-native-image-crop-picker to get image from gallery and trying to upload it on the server using Axios.But its not uploading to the server and when I hit the api to upload it starts sending and never-ending and no response getting from server.But when I try to make its build and then try to upload then its uploaded successfully and gettting reponse from server. Here is my code .

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

There are 1 answers

0
Zaid Qureshi On BEST ANSWER

I've solved it by commenting this line 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));
     }
   });