【问题标题】:React Native Expo - FileSystem readAsStringAsync Byte Allocation Failed (Out of Memory)React Native Expo - 文件系统 readAsStringAsync 字节分配失败(内存不足)
【发布时间】:2021-11-19 05:26:21
【问题描述】:

我正在使用带有 Expo 模块(文件系统和 Expo AV)的 React Native 创建一个 Android 应用程序,以使用手机的摄像头录制本地视频,然后将编码的 base64 视频发送到服务器。

发送base64字符串的代码如下:

const encodeBase64 = async () => {
  const fileUri = videoUri;
  const options = {
    encoding: FileSystem.EncodingType.Base64,
  };
  let result = await FileSystem.readAsStringAsync(fileUri, options);

  return result;
};

const upload = async () => {
  const base64 = await encodeBase64(videoUri);
  const result = await myAPI(base64);
}

它可以在我的手机(Oppo A3s)上运行,但在三星 A51 等另一部手机上,它会出现如下内存分配错误:

如何解决这个问题?

【问题讨论】:

    标签: javascript android reactjs react-native expo


    【解决方案1】:

    这是内存错误。 每部手机的存储空间都不同。 您可以使用块缓冲区。 因此,在这种情况下,您可以拆分 base64 数据以发布到服务器并在服务器中合并数据。

    ex: client=> chunkbuffer=>1024*100(size) 服务器=> 组合(客户端数据数组)

    祝你好运。 如果您有任何问题,请与我联系。 我会随时帮助你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 2018-02-05
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多