React Native:从CameraRoll.saveToCameraRoll解码图像数据时出错

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

我收到警告信号,说

Possible: Unhandled Promise Rejection: Error: Error decoding image data

这是我的代码。

for (let media of mediaArray) {   
  await CameraRoll.saveToCameraRoll(
    'https://someurl.mp4',
  ); 
}

我能够使它与具有.jpg的网址一起使用,但是当我尝试.mp4网址时,它不起作用。我知道网址正确,但是不确定为什么我会收到这个网址?如果我必须同时保存照片或视频,我会丢失某些东西吗?

ios reactjs react-native react-native-ios camera-roll
1个回答
0
投票

对于对此感兴趣的任何人,我发现CameraRoll不支持来自远程源的视频文件。

我所做的是使用rn-fetch-blog将文件保存到计算机,然后最终使用CameraRoll作为补充。

此片段使您可以浏览一系列照片和视频

selectedMedia.map(index => {
  let extension = cleanUrl.split('.').pop();
  RNFetchBlob.config({
    fileCache: true,
    appendExt: extension,
  })
    .fetch('GET', index.mediaUrl)
    .then(res => {
      // the temp file path
      CameraRoll.saveToCameraRoll(res.path());
    });
});
© www.soinside.com 2019 - 2024. All rights reserved.