react-native-fs: IOS file downloaded not able to be located on device

Hi there

Using a standard implementation to download files and save them locally on the device. When they are downloaded, I am not able to locate them on the device with for example “File Explorer” app, tried on emulator and physical iPad.

const urlExtensions = this.getUrlExtension(attachment.url);
      const localFile = `${RNFS.LibraryDirectoryPath}/${attachment.title}.${urlExtensions}`;
  
      const options = {
        fromUrl: attachment.url,
        toFile: localFile,
        fileCache: true
      };

      if (await RNFS.exists(localFile)) {
        FileViewer.open(localFile);
      } else {
        await RNFS.downloadFile(options).promise
        .then(() => { 
          FileViewer.open(localFile);
        })
        .then((res) => {
          // success
          // console.log("success");
        })
        .catch(error => {
          // error
          console.log("Attachment open error: ", error);
        });
      }

Also tried to use “DocumentDirectoryPath”, same issue.

Thanks in advance

Regards

About this issue

Commits related to this issue

Most upvoted comments

I was facing the same issue I followed this solution and it started working. You have to add Yes to “Supports opening documents in place” and “Application supports iTunes file sharing” in Info.plist file. Hope this solves your issue.

https://stackoverflow.com/questions/54626359/react-native-fs-ios-not-showing-files-in-the-document-directory

Is @FaisalAli19 's linked solution working for everyone? It didn’t work for me and I checked that the file is created in the DocumentDirectoryPath, and UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace are set to true/YES.

I had to use expo-sharing (I’m on bare workflow). It’s actually a good work-around for those who are struggling with the solution from Stackoverflow.

EDIT: The solution from Stackoverflow works for iOS <= 14. It is 15 that has tripped me up so far.

Thanks @FaisalAli19 , your solution worked for me with RNFS.DocumentDirectoryPath. By the way I got a ‘ENOENT: no such file or directory’ error message using RNFS.LibraryDirectoryPath

I solved this problem with share function, When you fetch the file on success it gives you path of the file where it is stored but you cant locate it physically to do so you have to take that path and call share using that link and then you can see the options to share that file and save in downloads.

fetchFile = (data) => { RNFetchBlob.config({ fileCache: true, addAndroidDownloads: { useDownloadManager: true, notification: true, mediaScannable: true, title: data?.originalname, path: ${dirs}/${data?.originalname}, }, }) .fetch('GET', data?.url) .then((res) => { if (Platform.OS === 'ios') { RNFetchBlob.ios.openDocument(res.data); return true; } else { console.log('The file saved to android ', res.path()); return true; } }) .catch((err) => { console.log('TCL:: fetchFile -> err', err); return true; }); };