Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova check if file in url exists

I am using cordova / phonegap and need to know if a file exists

Here's the code with the path and filename:

storeUrl = cordova.file.dataDirectory+'myfolder/myfile.mp3';

How can I check if this file exists?

like image 580
Satch3000 Avatar asked Jan 09 '16 10:01

Satch3000


1 Answers

Update: Works on iOS too.

Try:

function checkIfFileExists(path){
    // path is the full absolute path to the file.
    window.resolveLocalFileSystemURL(path, fileExists, fileDoesNotExist);
}
function fileExists(fileEntry){
    alert("File " + fileEntry.fullPath + " exists!");
}
function fileDoesNotExist(){
    alert("file does not exist");
}

Found the solution here.

Works on Android. Will test on iOS and update this answer.

like image 186
utamanna Avatar answered Oct 04 '22 04:10

utamanna