How to get Absolute path of a file in react-native?

后端 未结 4 741
独厮守ぢ
独厮守ぢ 2020-12-17 23:58

I am looking for a file picker in react-native which returns me Absolute Path of the file picked. I am currently using react-native-document-picker, but it gives me the rela

4条回答
  •  鱼传尺愫
    2020-12-18 00:50

    You may forget to request proper permissions for that like so (andriod only):

    export async function requestStoragePermission() {
    
        if (Platform.OS !== "android") return true
    
        const pm1 = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
        const pm2 = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
    
        if (pm1 && pm2) return true
    
        const userResponse = await PermissionsAndroid.requestMultiple([
            PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
        ]);
    
        if (userResponse['android.permission.READ_EXTERNAL_STORAGE'] === 'granted' &&
            userResponse['android.permission.WRITE_EXTERNAL_STORAGE'] === 'granted') {
            return true
        } else {
            return false
        }
    }
    

提交回复
热议问题