首页 > 解决方案 > 如何使用 rn-fetch-blob 在 React Native 中访问本地资产?

问题描述

我在使用 rn-fetch-blob 访问 React Native 中的本地资产时遇到问题,这是我的目录结构:

在此处输入图像描述

我想从 App.js 访问文件 female.png,这是我的脚本:

RNFetchBlob.fs.readFile('./female.png', 'base64')
    .then((data) => {
      console.log(data);
    })

我总是得到这个错误:

Possible Unhandled Promise Rejection (id: 14):
Error: No such file './female.png'; ./female.png (No such file or directory)
Error: No such file './female.png'; ./female.png (No such file or directory)
    at createErrorFromErrorData (blob:http://localhost:8081/61bf342c-3b22-4e66-9eea-bf93a115f88e:16416:17)
    at blob:http://localhost:8081/61bf342c-3b22-4e66-9eea-bf93a115f88e:16368:27
    at MessageQueue.__invokeCallback (blob:http://localhost:8081/61bf342c-3b22-4e66-9eea-bf93a115f88e:17245:18)
    at blob:http://localhost:8081/61bf342c-3b22-4e66-9eea-bf93a115f88e:16976:18
    at MessageQueue.__guard (blob:http://localhost:8081/61bf342c-3b22-4e66-9eea-bf93a115f88e:17149:13)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:http://localhost:8081/61bf342c-3b22-4e66-9eea-bf93a115f88e:16975:14)
    at http://localhost:8081/debugger-ui/debuggerWorker.js:80:58

请任何人帮助我使用 rn-fetch-blob 访问本地资产。

谢谢。

标签: react-nativereact-native-android

解决方案


推荐阅读