ngCordova checkFile not working


#1

Hello,

ng-cordova is awesome! I use the downloadFile and it works perfectly. I use it like so:

$cordovaFile.downloadFile(source, ‘cdvfile://localhost/persistent/myFolder/newFile.jpg’, true).then(…)…

But when I use $cordovaFile.checkFile(‘cdvfile://localhost/persistent/myFolder/newFile.jpg’).then(…), it always returns an error. It seems like it doesn’t find the file.

Am I doing it correctly? How do we check for a file using ng-cordova? The docs are sparse but pretty self-explanatory so I’m not sure what else to do. Google Groups on Phonegap don’t mention anything in this light. I’ve been testing different approaches and file/path referencing but nothing seemed to work. Any help would be much appreciated.

Thanks.


#2

I don’t think it is safe to user cdvfile:// …
Are you building on android or ios ? Try cordova recommended paths prefix like cordova.file.dataDirectory
http://plugins.cordova.io/#/package/org.apache.cordova.file
See Where to store files section


#3

Thanks for the reply Dipesh.

I am building for Android for now.

How do I use ‘cordova.file.dataDirectory’ in the $cordova.checkfile method?

Thanks?


#4

In case of android I have had troubles with cordova.file.documentsDirectory. Try cordova.file.externalRootDirectory
make sure you download your files in the same path

$cordovaFile.checkFile ( cordova.file.externalRootDirectory+‘filename.jpg’ ).then(function(result) { …


#5

I use the last example. But after creating a file (with the same url) a checkfile always returns a error 1 (NOEACC). So I can write to a file but cannot check it?.