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

Possible Unhandled Promise Rejection #484

Closed scrapecoder closed 2 years ago

scrapecoder commented 2 years ago

Bug report

Summary

Select_File = async () => {
    const { formData } = this.state;

    try {

        const res = await DocumentPicker.pick({
            type: [DocumentPicker.types.images, DocumentPicker.types.pdf]
        });

        this.setState({
            fileformData: [{ uri: res.uri, type: res.type, name: res.name }]
        });
    } catch (err) {

        if (DocumentPicker.isCancel(err)) {
            // User cancelled the picker, exit any dialogs or menus and move on
        } else {
            throw err;
        }
    }
};

Steps to reproduce

Whenever I'm calling Select_File fun, i'm getting warning Possible Unhandled Promise Rejection (id: 11): TypeError: null is not an object (evaluating 'RNDocumentPicker.pickDirectory') pickDirectory@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:202901:34 in emulator/real device. I also tried with the different versions of react-native-document-picker but I'm getting this warning in all versions.

Environment info

npx react-native info output:

"react": "16.9.0",
"react-native": "0.61.5",
"react-native-document-picker": "5.2.0",
vonovak commented 2 years ago

hello, can you please try with version 7 and report back? Thanks

scrapecoder commented 2 years ago

@vonovak I already tried but no luck

vonovak commented 2 years ago

What platform is it on?

Cavech84 commented 2 years ago

I have the same problem... "react": "17.0.2", "react-native": "0.64.2", "react-native-document-picker": "^7.1.0",

the result of DocumentPicker.pick is undefined :

const res = await DocumentPicker.pick({
            type: [
              DocumentPicker.types.pdf,
              DocumentPicker.types.doc,
              DocumentPicker.types.docx,
              DocumentPicker.types.ppt,
              DocumentPicker.types.csv,
              DocumentPicker.types.images,
              DocumentPicker.types.plainText,
              DocumentPicker.types.pptx,
              DocumentPicker.types.xls,
              DocumentPicker.types.xlsx,
            ],
          });
          console.log(
            res.uri,
            res.type, // mime type
            res.name,
            res.size,
          );
vonovak commented 2 years ago

hello, please read the docs for pick: https://github.com/rnmods/react-native-document-picker#documentpickerpickmultipleoptions--documentpickerpicksingleoptions--documentpickerpickoptions

it returns an array, not an object.

Thank you! :)