如何阅读React Native的文件内容? // react-native-f不起作用

发布于 2025-02-06 21:18:30 字数 964 浏览 0 评论 0原文

我目前正在处理一个反应本应用程序,该应用程序要求用户从其手机中选择文本文件并阅读它,我已经实施了该部分,要求用户使用expo-cocument-picker < /代码>,但我无法读取文件内容。

我已经尝试使用react-native-fs而没有任何成功:

            const content = async (file_path) => {
                let response = undefined;
                try {
                    response = await RNFS.readFile(path);
                } catch (err) {
                    showAlert("Failed to read file")
                    throw err;
    
                }
                return response;
            }

我得到的只是以下错误:

null不是对象(评估rnfsmanager.rnfsfiletypereperegular)

此时已经阅读了与该问题有关的所有问题和堆叠式帖子,但是建议的解决方案(例如npm install-save react-native-fs 或重置高速缓存都行不通。

也许是因为我使用博览会?如何读取文件whitout react-native-fs?

编辑:我已经尝试使用 filesystem 与函数readAssTringAsync,但它始终返回以下内容:{“ _ u”:0,“ _v”:0,” _w“:null,” _x“:null}”

我感谢帮助!

I am currently working on a react-native application that is asking the user to pick a text file from its phone and read it, I already implemented the part that ask the user to choose a file using expo-document-picker but I cannot manage to read the file content.

I already try using react-native-fs without any success :

            const content = async (file_path) => {
                let response = undefined;
                try {
                    response = await RNFS.readFile(path);
                } catch (err) {
                    showAlert("Failed to read file")
                    throw err;
    
                }
                return response;
            }

All I get is the following error :

null is not an object (evaluating RNFSManager.RNFSFileTypeRegular)

At this point I have read every issues and stackOverflow post related to the problem but the suggested solutions like npm install --save react-native-fsor reseting the cache does not work.

Perhaps it is because I use expo ? How can I read a file whitout react-native-fs ?

edit : I already tried to use FileSystem with the function readAsStringAsync but it always return the following : {"_U":0, "_V":0, "_W": null, "_X": null}"

I appreciate the help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文