Search code examples
reactjsreact-nativeuidocument

DocumentPicker got NULL for file


I tried to get Data of the Document but I only get Null.
Documentpicker is working, except: The Selected Data is NULL.

async openDocumentReader() {
    try {
        const res = await DocumentPicker.pick({
            type: [DocumentPicker.types.csv],
        });
        console.log(
          res.uri,
          res.type,
          res.name,
          res.size,
        );
        if (res.name == null) {
            Alert.alert('Document is Null');
        }
    } catch (err) {
        if (DocumentPicker.isCancel(err)) {
            //User canceld
        } else {
            throw err;
        }
    }

Any recommendations?


Solution

  • I found a solution: I had to choose pickSingle for it.

    try {
        const res = await DocumentPicker.pickSingle({
            type: [DocumentPicker.types.csv], mode : 'import', copyTo: 'documentDirectory',
        });
        var uri = res.uri;
        var name = res.name;
        var fileCopyUri = res.fileCopyUri;
        console.log(JSON.stringify(res));
        console.log(res.uri); 
    }
    

    Or something like that.