首页 > 解决方案 > 我如何在本机反应时读取文件?

问题描述

我想像这样在 react-native 读取文件 mp3 文件,我该怎么做。

<Buffer 75 64 e5 be 9b 6d e4 84 97 a3 10 61 50 07 13 72 b9 ca 95 56 a0 42 4b e7 23 ea 6a 09 cb 9c 4c 3f ac 9f 70 b8 f8 56 89 d8 2e 09 79 60 42 04 d0 91 22 dd ... 52499 more bytes>

标签: react-native

解决方案


如果文件很大,您可以在从文件读取时定义您的类型,如果文件很大,您应该考虑使用readStream

RNFetchBlob.fs.readFile(PATH_TO_READ, 'base64')
.then((data) => {
  // handle the data ..
})

编辑:我认为这个答案会帮助你解决这个问题

react-native-fs:如何读取本地图片(获取本地文件的base64)


推荐阅读