HTML5 API checks if a file exists

I have a temporary storage of file APIs (HTML5), but I canโ€™t check if the file exists or not. Is there an easy way to check this? Should I really try and read the file to find out?

The search around gave me nothing concrete

Synchronous checking would be good, is this possible?

+6
source share
1 answer

You must read the file. The following example is based on this demo from HTML5Rocks (it catches all errors, you can filter various types of errors ):

var errorHandler = function() { // File is not readable or does not exist! }; fs.root.getFile('log.txt', {}, function(fileEntry) { fileEntry.file(function(file) { var reader = new FileReader(); reader.onloadend = function() { // The file exists and is readable }; reader.readAsText(file); }, errorHandler); }, errorHandler); 

The synchronous method is available only to web workers due to their blocking nature. Error handling is slightly different .

+7
source

Source: https://habr.com/ru/post/915021/


All Articles