问题描述
我已经退出了博览会的项目.
I have ejected project of the expo.
更改 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.
与存储许可有关吗?
需要帮助....?
推荐答案
您可以使用Carlo提到的react-native-fs或 rn-fetch-blob ,我建议您使用rn-fetch-blob来读取文件,您可以检查其文档,就像这样
You can use react-native-fs as Carlo mentioned or rn-fetch-blob, I recommend rn-fetch-blob, to read a file u can check their documentation, it goes something like this
let data = '';
RNFetchBlob.fs.readStream( ...options).then((ifstream) => {
ifstream.open()
ifstream.onData((chunk) => {
data += chunk
// show progress ...%
})
ifstream.onError((err) => {
console.log('oops', err)
})
ifstream.onEnd(() => {
consol.log('final data', data)
})
}))
这篇关于如何从URI获取文件.世博会|反应本机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!