You get FileError.SECURITY_ERR
because you are not allowed to run this code locally. You will see an error if you did not have empty error handlers.
You will see an error if you save the following code in a local file and run it in chrome:
<html> <script> function doit() { function errorHandler(e) { var msg = ''; switch (e.code) { case FileError.QUOTA_EXCEEDED_ERR: msg = 'QUOTA_EXCEEDED_ERR'; break; case FileError.NOT_FOUND_ERR: msg = 'NOT_FOUND_ERR'; break; case FileError.SECURITY_ERR: msg = 'SECURITY_ERR'; break; case FileError.INVALID_MODIFICATION_ERR: msg = 'INVALID_MODIFICATION_ERR'; break; case FileError.INVALID_STATE_ERR: msg = 'INVALID_STATE_ERR'; break; default: msg = 'Unknown Error'; break; }; console.log('Error: ' + msg); } window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, function(fs) { fs.root.getFile('test', {create: true}, function(fileEntry) { fileEntry.createWriter(function(fileWriter) { var builder = new WebKitBlobBuilder(); builder.append("Saurabh"); builder.append("\n"); builder.append("Saxena"); var blob = builder.getBlob('text/plain'); fileWriter.onwriteend = function() { </script> <body onload="doit();"> </body> </html>
source share