如何从 URI 中获取文件 |世博会|反应原生 [英] How to get file from URI | Expo | React Native

查看:33
本文介绍了如何从 URI 中获取文件 |世博会|反应原生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已退出世博会项目.

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

After changing info.plist, now I am able to get my app in the list of "open with app list" and actually able to open that file with my expo(React native app).

App.js

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

}).catch(err => console.error('An error occurred', err));

这段代码给了我这个 URL.

this code is giving me this URL.

file:///private/var/mobile/Containers/Data/Application/7E55EB55-7C49-4C0C-B4CB-63AC4F49689E/Documents/Inbox/matters-3.csv

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

So, that means now I have URL of the email attachment, but How am I able to get the data of that csv string in my app?

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

So I am assuming, when I click open with my app. The URL that is passed into my app from the system is actually a copy of the document that is placed somewhere in our app’s directory.

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

But when I trying to access this file with Expo.FileSystem. readAsStringAsync it's giving me an error says, the file is not readable.

与存储权限有什么关系吗?

需要帮助....?

推荐答案

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

I think you could use react-native-fs. This here should work and print out the contents of the CSV file to the console.

App.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));

这篇关于如何从 URI 中获取文件 |世博会|反应原生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆