0

I am trying to download image using rn-fetch-blob library but it is not getting downloaded from my server. The same code is working well with android but not on iOS. I am also using camera roll to save the image in the gallery but it is throwing the error Could not find image . What am I doing wrong?

Download code

   function DownloadImage(url,id){
    let imgUrl = url;

    let newImgUri = imgUrl.lastIndexOf('/');
    let imageName = imgUrl.substring(newImgUri);
    let dirs = RNFetchBlob.fs.dirs;
    let path = Platform.OS === 'ios' ? dirs['DownloadDir'] + imageName : dirs.PictureDir + imageName;   
        RNFetchBlob.config({
          fileCache: true,
          appendExt: 'png',
          path: path,
    
        }).fetch("GET", imgUrl).then(res => {
         CameraRoll.save(res.path()).then(()=>{
            }).catch((ex)=>{
                alert("Error="+ex);
            });
        }).catch(error=>{
            obj.loadingflag=false;
            alert(error);
        });
        
   }
Knevagi
  • 157
  • 1
  • 1
  • 13

1 Answers1

0

ifaced the same issue on IOS. solution is on response you have to do this

.then(resp => {
      // console.log(resp);
      if (Platform.OS === "ios") {
        RNFetchBlob.ios.openDocument(resp.data);
      }
    })

you can refer my answer stack overflow response

Gaurav Roy
  • 11,175
  • 3
  • 24
  • 45
  • does this `RNFetchBlob.ios.openDocument(resp.data)` need to be before camera roll.save? Because I tried doing that and even though a blank document I being opened but I am still getting the error on camera roll.save – Knevagi Apr 21 '21 at 10:35