iosreactjsreact-nativereact-native-ioscamera-roll

React Native: Error decoding image data from CameraRoll.saveToCameraRoll


I'm getting a warning sign, saying

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

This is my code.

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

I was able to get this to work with a url that has a .jpg, but when I tried a .mp4 url, it doesn't work. I know the url is correct, but not sure why I'm getting this? Am I missing something if I have to save both either photo or video?


Solution

  • For anyone that was interested in this, I found out that CameraRoll doesn't support video files that are coming from remote sources.

    What I did was use rn-fetch-blog to save the file into the computer and then finally used CameraRoll as a supplement.

    This snippet allows you to go through an array of photos and videos

    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());
        });
    });