Eric dos Reis
Eric dos Reis

Reputation: 57

Nothing happens when trying to move a file with ng-cordova in Android

I'm trying to move a image stored in "temp files" directory to a directory created in file system, but nothing happens, the promise doesn't return error and success, absolutely nothing happens.

The cordova file plugin was added in my app:

enter image description here

I debugged the app in my device with Android Studio, and I saw an error in log cat:

enter image description here

"Error in Success callbackId: File285873816 : TypeError: fileSystem.getFile is not a function" in source: file:///android_asset/www/cordova.js

I gave an alert to display the fileSystem object in the callback function in ng-cordova.js, and this object don't contains the getFile() function:

$window.resolveLocalFileSystemURL(path, function (fileSystem) {
    alert("fileSystem " + JSON.stringify(fileSystem));

Someone can help me?

Upvotes: 0

Views: 461

Answers (3)

Fuat
Fuat

Reputation: 809

You JSON file is not well-formed. Check all of them.

In my case I saw an meaningless text ("asd") at the end of Json file after last "}" So I added console log for and detected which JSON is wrong. And removed wrong text in it.

Upvotes: 1

Eric dos Reis
Eric dos Reis

Reputation: 57

It was my mistake, in the function moveFile, I was sending the directory with the name of the file, in the moveFrom parameter in my service. The correct way is set only the directory:

$cordovaFile.moveFile(moveFrom, currentFileName, cordova.file.dataDirectory + moveTo, newFileName)
  .then(function (success) {
      alert("Yeah Success " + JSON.stringify(success));
  }, function (error) {
      alert("Fucking error " + JSON.stringify(error));
  });

Cordova file could return an invalid directory error.

Thanks for your attention.

Upvotes: 0

travelerg17
travelerg17

Reputation: 31

Make sure you actually installed the plugin in your project. In my experience ng-cordova helps with the integration but you still need to add the plugin.

Upvotes: 0

Related Questions