Jump to content
Sign in to follow this  
cve60069

HTML5 requestFileSystemSync

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>

Share this post


Link to post
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>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...