我正在通过React Native中的ImagePicker从移动本地存储获取视频,现在我想将此视频转换为base64,但无法做到。
实现的代码是:
ImagePicker.launchImageLibrary(
{ mediaType: 'video', includeBase64: true },
(response) => {
try {
RNFetchBlob.fs
.stat(response.assets[0].uri)
.then((res) => {
//"res.path" will give me original path of video.
})
.catch((err) => {});
} catch (Excepstion) {}
}
);
查看 react-native-fs 包。并使用它:
import RNFS from 'react-native-fs';
...
// readFile(filepath: string, encoding?: string)
RNFS.readFile(filePath, 'base64').then(res => {
...
})
.catch(err => {
...
console.log(err.message, err.code);
...
});
希望这对您有用。