Check if local file exists (HTML5 FS API)

I am developing a Chrome extension and I want to check if a file exists. I do not want to do anything with the file: I only want to check its existence.

If I use XMLHttpRequest, it does not work because it is forbidden for security reasons. Therefore, I have to use the HTML5 FS API. The problem is that this API has no way to check if a file exists.

I have a variable called "fileExists" and I would like to know how to change its value from false to true or from true to false depending on the availability of the file (determined by the URL).

Thank.

+5
source share
1 answer

use something like:

   function exists(fileName, callback) {
        storageRootEntry.getFile(fileName, {create : false}, function() {
            callback(true);
        }, function() {
            callback(false);
        });
    }

storageRootEntry - . "true", , "false" . {create : false}

+13

All Articles