Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS file downloaded not able to be located on device #897

Open
Znow opened this issue Jun 23, 2020 · 18 comments
Open

IOS file downloaded not able to be located on device #897

Znow opened this issue Jun 23, 2020 · 18 comments

Comments

@Znow
Copy link

Znow commented Jun 23, 2020

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

@exotexot
Copy link

But did you check if the file exists at the given path?

@Znow
Copy link
Author

Znow commented Jun 24, 2020

At which path? I'm able to view the file in my application...

@gauravsbagul
Copy link

Hello, I am having same issue, cant locate file on device. I am using this path RNFetchBlob.fs?.dirs?.DownloadDir

     ` downloadSupplementFile = async (data) => {
	const dirs = RNFetchBlob.fs?.dirs?.DownloadDir;
	try {
		  this.fetchFile(data, dirs);
	      } catch (err) { }
 };
 
      fetchFile = (data, dirs) => {
	RNFetchBlob.config({
		fileCache: true,
		addAndroidDownloads: {
			useDownloadManager: true,
			notification: true,
			mediaScannable: true,
			title: data?.originalname,
			path: `${dirs}/${data?.originalname}`,
		},
	})
		.fetch('GET', data?.url)
		.then(async (res) => {
			try {
				if (Platform.OS === 'ios') {
					const file = res.path();
					let base64 = await res.base64();
					let len = await RNFetchBlob.fs.writeFile(file, base64, 'base64');
					return true;
				} else { return true}
			} catch (error) {
			}
		})
		.catch((err) =>  return true );
};`

@gauravsbagul
Copy link

gauravsbagul commented Jul 7, 2020

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

@DracotMolver
Copy link

Having the same issue. In android it downloads the file perfectly in the specified folder. In iOS it says downloaded but it is nowhere saved :/

@FaisalAli19
Copy link

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

@DracotMolver
Copy link

@FaisalAli19 solution worked perfectly. The issue should be closed I guess.

@kotunde
Copy link

kotunde commented Feb 3, 2021

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

@shahanshah87
Copy link

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

Did you find any solution for this?

@aprilmintacpineda
Copy link

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

This works, now I only have android as the problem.

@UVStudio
Copy link

UVStudio commented Jan 28, 2022

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.

@iamrohitagg
Copy link

I've tried all the solutions in the thread and none of them worked for me. I've tested on iOS 15.
Please help!

@HexNeck
Copy link

HexNeck commented Jan 31, 2023

Same for me :( I can't see the file I'm saving

@Niltonsf
Copy link

Bump

1 similar comment
@roderickmonk
Copy link

Bump

@BouarourMohammed
Copy link

Same for me :( I can't see the file I'm saving

@Lixus
Copy link

Lixus commented Mar 27, 2024

Did someone find a solution here? I have the same problem on my iOS devices. The additions to the plist did not help.

@Znow
Copy link
Author

Znow commented Apr 2, 2024

4 years later... and still no response from author @itinance, along with the other 544 issues...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests