react-native - 如何使用 React Native 读取以 ph:// 开头的文件作为 base64 字符串?
问题描述
我正在尝试读取ph://
以 RNFS 开头的图像文件并将它们转换为 base64 字符串,但不幸的是我得到了ENOENT: no such file or directory
错误。
如何读取这些文件并将它们转换为 base64?
解决方案
您可以使用react-native-convert-ph-asset
import RNConvertPhAsset from 'react-native-convert-ph-asset';
const convertLocalIdentifierToAssetLibrary = async (localIdentifier) => {
return await RNHeicConverter.convert({
// options
path: localIdentifier,
});
};
然后使用 react-native-fs 将其转换为 base64
const base64 = await RNFS.readFile(newpath.path, 'base64');[enter link description here][2]
推荐阅读
- c# - 如何为使用同一键盘的 2 名玩家分配不同的控制方案?
- selenium - 硒 XPATH 匹配
- python - 如何获取作为神经网络输出的向量的一部分?
- reactjs - 当过滤器应用于选项卡内的列表时,React-Admin 正在刷新整个屏幕
- mysql - 即使使用索引,此查询也相对较慢。如何加快速度?
- fedora - 在 Fedora 33 上的 Raspberry PI 4 上运行 mysql 客户端是否有问题
- semaphore - binary semphore - 当我们连续执行 2 sem_up 然后 2 down 时会发生什么?
- c# - Listview 不会根据 ObservableCollection 属性进行更新
- java - 如何使用 @Where 注释来连接两个表(父实体和目标实体)列?
- javascript - 开玩笑:提供的元素或 ID 无效。(视频)