如何从URI获取文件 世博会| 反应原生

Rut*_*tel 6 filesystems ios react-native expo

我已经放弃了世博会的项目.

更改info.plist后,现在我可以将我的应用程序放在"打开应用程序列表"列表中,并且实际上能够使用我的expo(React本机应用程序)打开该文件.

App.js

Linking.getInitialURL().then((url) => {
  if (url) {
        console.log(url);
    }

}).catch(err => console.error('An error occurred', err));
Run Code Online (Sandbox Code Playgroud)

这段代码给了我这个URL.

file:///private/var/mobile/Containers/Data/Application/7E55EB55-7C49-4C0C-B4CB-63AC4F49689E/Documents/Inbox/matters-3.csv
Run Code Online (Sandbox Code Playgroud)

所以,这意味着现在我有电子邮件附件的URL,但我怎样才能在我的应用程序中获取该csv字符串的数据?

所以我假设,当我点击打开我的应用程序.从系统传递到我的应用程序的URL实际上是放在我们应用程序目录中某处的文档的副本.

但是当我尝试使用Expo.FileSystem访问此文件时.readAsStringAsync它给我一个错误说,该文件是不可读的.

是否与存储权限有关?

需要帮忙....?

cro*_*mir 1

我认为你可以使用react-native-fs。这里应该可以工作并将 CSV 文件的内容打印到控制台。

应用程序.js

var RNFS = require('react-native-fs');

Linking.getInitialURL().then((url) => {
  if (url) {
    RNFS.readFile(url).then((data) => {
      console.log(data);
    }

}).catch(err => console.error('An error occurred', err));
Run Code Online (Sandbox Code Playgroud)