react-native-documents / document-picker

Document Picker for React Native
https://react-native-documents.github.io/
MIT License
1.35k stars 437 forks source link

not able to upload PDF on android using REST API. #597

Closed virenradadiya closed 1 year ago

virenradadiya commented 1 year ago

Bug report

Sometimes I am not able to upload PDFs on android using REST API(Formdata) but in IOS it's working fine. I am getting a network error when I am uploading any file the first time it's working fine but when I am trying to upload multiple times at that time I am getting a network error.

Describe what you expected to happen: I am simply trying to upload PDF using fetch but sometimes I am getting a network error in the catch block. I am trying with the XMLHttpRequest and Axios also but the same issue happens.

CODE Example

i am padding form data like :

  const onPresschoosePdf = async () => {
    try {
      const res = await DocumentPicker.pickSingle({
        presentationStyle: "fullScreen",
        type: [types.pdf],
        copyTo: "documentDirectory",
      });
      let formdata = new FormData();
      formdata.append("medical_record1", {
        uri: res.uri,
        name: res.name,
        type: res.type,
      });
      //API call function 
    } catch (err) {
      console.log("PDFFF Error::>", err);
    }
  };

Screenshot 2022-10-19 at 3 55 43 PM

Error

Screenshot 2022-10-19 at 3 59 36 PM

Environment info

npx react-native info output:

System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1
    Memory: 173.22 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 18.7.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.15.0 - /opt/homebrew/bin/npm
    Watchman: 2022.08.22.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9014738
    Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.11 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.68.2 => 0.68.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

library version: v8.1.1

iOS / Android version: x.x

vonovak commented 1 year ago

Hello and thanks for reporting, please try using the latest version of the package. Also, for your purpose you probably don't need to use the copyTo option.

Also, please make sure that you're using the fetch that comes with react native, not something else.

If that doesn't work, I'm afraid I cannot help unless I have the code - the issue is outside of this package and without code that I can run locally I cannot say more.

Thank you 🙂

alex-mironov commented 1 year ago

@vonovak can you please suggest what is the issue with axios? I've spotted that in my case axios doesn't work either, even though request with native fetch was successful.