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

后端 未结 4 742
独厮守ぢ
独厮守ぢ 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:29

    Try this, maybe it will help you https://www.npmjs.com/package/react-native-file-share-for-android But its support only for Android

    const uploadDocunment = async finalSubmit => {
          const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
            {
              title: 'Storage Permission',
              message: 'App needs access to memory to download the file ',
            },
          );
          if (granted != PermissionsAndroid.RESULTS.GRANTED) {
            ToastAndroid.showWithGravity(
              'You need to give storage permission to download the file',
              ToastAndroid.SHORT,
              ToastAndroid.BOTTOM,
            );
            return false;
          }
          try {
            DocumentPicker.pick({
              type: [DocumentPicker.types.plainText],
            }).then(res => {
              RNFetchBlob.fs.readFile(res.uri, 'utf8').then(text1 => {
                ToastAndroid.showWithGravity(
                  'Docunment is Ready!',
                  ToastAndroid.SHORT,
                  ToastAndroid.BOTTOM,
                );
              });
            });
          } catch (err) {
            if (DocumentPicker.isCancel(err)) {
              ToastAndroid.showWithGravity(
                'File not Selected',
                ToastAndroid.SHORT,
                ToastAndroid.BOTTOM,
              );
            } else {
              throw err;
            }
          }
        };
        uploadDocunment();
      };
    

提交回复
热议问题