Jump to content

HTML5 requestFileSystemSync


cve60069

Recommended Posts

Hello I am wanting to write to a Sync file using the Filesystem API (I am using Chrome) and I cannot get past the first hurdle - creating a file system. I wrote this little prog to develop the functions and I cannot get to the second-alert in the function doFile(). Any tips where I am going wrong, please? Regards <html><head><script type="text/javascript"></script><script>function doFile(){alert("doFile")var fs = requestFileSystemSync(TEMPORARY, 1024*1024);alert()} // end doFile</script></head> <body><input type="button" onclick="doFile()"/></body></html>

Link to comment
Share on other sites

http://www.html5rock...ile/filesystem/ Chrome File API stores files as blob, for e.g you create abc.txt then the link to access maybe like this C:\Users\{your account}\AppData\Local\Google\Chrome\User Data\Default\File System\001\t\00\00000002 Here is the code I tested before
<script>var fs = null;// Check for the various File API support.if (window.File && window.FileReader && window.FileList && window.Blob) {  // Initiate filesystem on page load.  initFS();} else {  alert('The File APIs are not fully supported in this browser.');}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);} function initFS() {   window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, function(filesystem) {   fs = filesystem;   }, errorHandler);} function writeFile(path, content){  fs.root.getFile('log1.txt', {create: true}, function(fileEntry) {   fileEntry.createWriter(function(fileWriter) {	fileWriter.onwriteend = function(e) {	 console.log('Write completed.');	};	fileWriter.onerror = function(e) {	 console.log('Write failed: ' + e.toString());	};	var bb = new window.WebKitBlobBuilder();	bb.append(content);	fileWriter.write(bb.getBlob('text/plain'));   },   errorHandler);   fs.root.getDirectory(path, {create: true}, function(dirEntry) {	fileEntry.moveTo(dirEntry);	console.log('in');   },   errorHandler);  },  errorHandler);} </script><button onclick="writeFile('file-api/', 'blah blah blah')">Test FileAPI</button>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...