Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

err Error: ENOENT: no such file or directory #2

Open
shimangdian opened this issue Dec 30, 2020 · 3 comments
Open

err Error: ENOENT: no such file or directory #2

shimangdian opened this issue Dec 30, 2020 · 3 comments

Comments

@shimangdian
Copy link

shimangdian commented Dec 30, 2020

hello ,when i use this lib chose a folder and react-native-fs to downloadFile, i get this error:

err Error: ENOENT: no such file or directory, open 'content://com.android.externalstorage.documents/tree/15F4-2D1A%3ADownload/document/15F4-2D1A%3ADownload/'

there is my code:

selectDirectory().then((path) => {
                console.log(path);
                //
                const downloadDest = `${path}/`;
                //
                const options = {
                    fromUrl: url,
                    toFile: downloadDest,
                    background: true,
                    begin: (res) => {
                        console.log('begin', res);
                        console.log('contentLength:', res.contentLength / 1024 / 1024, 'M');
                    },
                    progress: (res) => {
      
                        let pro = res.bytesWritten / res.contentLength;
                        console.log('pro==', pro);
                    },
                };
                try {
                    const ret = RNFS.downloadFile(options);
                    ret.promise
                        .then((res) => {
                            console.log('success', res);
                            console.log('file://' + downloadDest);
                        })
                        .catch((err) => {
                            console.log('err', err);
                        });
                } catch (e) {
                    console.log(e);
                }
            });

can i get any help?

@shimangdian
Copy link
Author

My environment is Android, simulator

@crutchcorn
Copy link
Member

Unfortunately, the method we're using for directory picking is based off of SAF. While this works for some instances, RNFS does not support SAF at the moment (to the best of our knowledge).

This library is in severe need of documentation - it's something on our todo list that explains the limitations, real-world usages, and future roadmap

In the meantime, however, I would suggest against using this library. Maybe I can point you towards how we're using a non-SAF directory picker in our app, GitShark?


Android

For Android:


iOS

However, for iOS, we found that it was not advantageous from a UX perspective to implement a directory picker (again, for a myriad of reasons that will be in the future blog post). Instead, for our usage we simply drop files into our app's directory and disallow users to select folders. This requires two changes:

  1. An Info.plist change
  2. Use DocumentDirectoryPath as the base path for any iOS files:
import {DocumentDirectoryPath} from 'react-native-fs';

const filePath = `${DocumentDirectoryPath}/folder/file.ts`;

Full example

This way, they're accessible from the Files app easily without too much development hastle

@shimangdian
Copy link
Author

will ~ thx .
Actually I don’t have any native development experience.
Maybe i will find other lib. ahahahah
Finally, thank you again.

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

No branches or pull requests

2 participants