如何在React Native中将视频(来自移动存储)转换为base64?

问题描述 投票:0回答:1

我正在通过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 video base64
1个回答
5
投票

查看 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);
    ...
});

希望这对您有用。

© www.soinside.com 2019 - 2024. All rights reserved.