React Native get real path of file on Android

Viewed 31

I'm using react-native-document-picker to select a file and react-native-fs to upload the file.

try {
        const res = await DocumentPicker.pick({
        type: [DocumentPicker.types.allFiles],
        copyToCacheDirectory: false
    });

I'm getting the uri as - content://com.android.providers.media.documents/document/image%3A24

Then I'm converting this to actual path using react-native-get-real-path.

RNGRP.getRealPathFromURI(res[0].uri)
        .then(filePath =>{
          realFilePath = filePath
          console.log("real-path-->"+filePath)
          ToastAndroid.show(filePath, ToastAndroid.SHORT);
        })
  1. The above method gives the path as /storage/emulated/0/Download/output-onlinepngtools.png but this working for few files, for others I'm getting null as the real-path.

  2. This is the error I see while uploading the file - [Error: Socket is closed]

0 Answers
Related