paandahl / react-native-filesystem

Simple file system API for iOS & Android.
Apache License 2.0
71 stars 26 forks source link

Question: Find saved file on Android 7 #8

Open ghost opened 7 years ago

ghost commented 7 years ago

Is there a way to locate the saved file using a File Manager. I'm using storage option FileSystem.storage.important but can't find it anywhere. Use case: transfer file to a computer

ghost commented 7 years ago

I'm wondering whether this library works at all on Android 7?

saveToFile = async(data) => {
        const fileContent = JSON.stringify(data);
        await FileSystem.writeToFile('data/test-2.txt', fileContent, FileSystem.storage.important);
        console.log('file is saved!!!!!!!!!!')
    }

logs indeed file is saved. However,

readFromFile = async() => {
        const fileContent = await FileSystem.readFile('data/test-2.txt');
        console.log('data from file')
        console.log(fileContent)
    }

yields an unhandled promise rejection warning:

File was not found: data/test-2.txt

paandahl commented 7 years ago

You have to read the file from the same storage class as it is written. In your case:

const fileContent = await FileSystem.readFile('data/test-2.txt', FileSystem.storage.important);
ghost commented 7 years ago

My bad, thanks.

Back to my first question: Is there a way to locate the saved file from Android File Manager or any third party File Manager?

paandahl commented 7 years ago

I'm not very familiar with these File Managers, but I would very much assume so. If you look at the API Reference, it says something about the location of the different storage classes, and the abolutePath-method will give you the exact location of the file.