React-native-fs: writeFile not working in new version

Created on 27 Jun 2017  路  13Comments  路  Source: itinance/react-native-fs

What means that the last version Removed attributes from writeFile and appendFile? I want to use writeFile in version 2.3.2 function but is not working anymore.

more info needed question

Most helpful comment

@fredbt MainBundlePath is not defined on Android as stated in README:

_

On Android, use "RNFS.DocumentDirectoryPath" (MainBundlePath is not defined)

_

All 13 comments

Whats your code?

I have the same feeling that writeFile is no longer working:

I just did this:

      RNFS.writeFile(RNFS.DocumentDirectoryPath + '/test.txt', 'teste', 'ascii')
        .then((success) => {
          console.log('FILE 2 WRITTEN!')
        })
        .catch((err) => {
          console.log(err.message)
        })

In the console, I see "FILE 2 WRITTEN".

However, when I go to the "Explore" of my cell hone (and/or the emulator), I don't see any files. Screenshot of the file system storage of my emulator for the app I'm working on right now ...

screenshot from 2017-08-24 17-30-03

I'm doing the same of @fredbt. Working with RN 0.41

Just to add more info, this is my setup:

"react": "16.0.0-alpha.12",
"react-native": "^0.46.4",
"react-native-fs": "^2.5.1",

I also tried to write in ExternalDirectoryPath and I could not find the files. Another data point: RNFS.MainBundlePath is "undefined" for me: console.log(RNFS.MainBundlePath) shows "undefined" in the console, in this setup.

@fredbt I recommend you to check react-native-fetch-blob. I changed the library due I needed a fast solution

Thanks @agrass
I will try it, then.

@fredbt MainBundlePath is not defined on Android as stated in README:

_

On Android, use "RNFS.DocumentDirectoryPath" (MainBundlePath is not defined)

_

Thanks @itinance !
I will send a PR changing the README to also add this info in the constants section!
https://github.com/itinance/react-native-fs#constants

much appreciated

https://github.com/itinance/react-native-fs/pull/338 all yours @itinance :)

The same issue... Ondroed 4.4.2

"react-native": "0.53.0",
"react-native-fs": "2.9.11"

It is 100% working code. I have also same issue in signature image save.

import RNFS from 'react-native-fs';
const file_path = RNFS.DocumentDirectoryPath + "/customer_signature.png";
RNFS.writeFile(file_path, result.encoded, 'base64').then(()=>{

        console.log('onSaveEvent success', file_path)
        thisThat.props.updateSignature(true, file_path);
    }).catch((error) => {
        console.log('onSaveEvent error', error)
        thisThat.props.updateSignature(true, '');
    });

It is 100% working code. I have also same issue in signature image save.

import RNFS from 'react-native-fs';
const file_path = RNFS.DocumentDirectoryPath + "/customer_signature.png";
RNFS.writeFile(file_path, result.encoded, 'base64').then(()=>{

        console.log('onSaveEvent success', file_path)
        thisThat.props.updateSignature(true, file_path);
    }).catch((error) => {
        console.log('onSaveEvent error', error)
        thisThat.props.updateSignature(true, '');
    });

Similar issue using latest version

Was this page helpful?
0 / 5 - 0 ratings