【问题标题】:DocumentPicker got NULL for fileDocumentPicker 为文件获取 NULL
【发布时间】:2022-01-23 21:37:26
【问题描述】:

我试图获取文档的数据,但我只得到 Null。
Documentpicker 正在工作,除了:所选数据为 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;
      }
    }

有什么建议吗?

【问题讨论】:

  • 您使用的是哪个文档选择器模块?
  • 我已经发现了这个问题,我会在下面发布我不太花哨的解决方案

标签: reactjs react-native uidocument


【解决方案1】:

我找到了解决方案: 我不得不为它选择pickSingle。

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); }

或者类似的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 2015-02-08
    相关资源
    最近更新 更多