How to use the native File class

Hi,

I am trying to implement the moveFile function from the native File class, but I can’t get it to work, saying that the moveFile function does not exist. I am probably overlooking something here, but I can’t seem to find it.

I tried to use:

cordova.file.moveFile(path, filename, newPath, newFileName)

File.moveFile(path, filename, newPath, newFileName) (Importing the File class from ionic-native didn’t do it either)

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
         console.log('file system open: ' + fs.name);
         fs.moveFile(path, filename, newPath, newFileName).then(
                (success) => console.log(success),
                (err) => console.log(err)
         );
}, console.log('filesystem not open'));

and finally

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
         console.log('file system open: ' + fs.name);
         fs.root.moveFile(path, filename, newPath, newFileName).then(
                (success) => console.log(success),
                (err) => console.log(err)
         );
}, console.log('filesystem not open'));

Can anyone help me out here? Thanks!

Hmm, moveFile is there, so it shouldn’t be throwing errors.

It seems to be the File class itself. When I import it from ionic-native it throws an error:

ionic-app/node_modules/ionic-native/dist/index has no exported member 'File'

I reinstalled the plugin but no luck yet. I am using the 2.0.0-beta.25.

I have done some more digging in the node_modules, searching for the ionic-native map. In ionic-native/dist/plugins, I do not see any file.js, file.d.ts or file.js.map, the files other plugins do have.

In ionic/native/dist, the index.js file contains links to a File class, but it is commented out as seen below.

Other ionic-native plugins install fine. Is this normal or does this have something to with my problem?

@kristofsw It seems that you’re using an old release of ionic-native. The File plugin (partial) implementation was added in mid-March (see the following commit). You should update the ionic-native package to the latest version, i.e. execute the following command from inside of your project’s folder:

npm update ionic-native --save

Awesome, that worked! Thank you!