Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
DigitalMaestro
Posts: 38
Registered: ‎03-07-2012
My Device: Dev Alpha B, Playbook 16GB, Z10 LE

HTML 5 FileWriter size limit

[ Edited ]

I am having a problem writing out files from my application.  No matter what I try , I cannot seem to create a file that is bigger than 448kb  Is there a limitation or a bug in the BB10 FileWriter implementation that is causing this or is there an error in my code?  Please find my code snippet below.  Any help is greatly appreciated.

 

	     blackberry.io.sandbox = false;
	    	
	     window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
	     var writeFileSystem = function (fs) {
             // in order to access the shared folder,
             // config.xml must declare the "access_shared" permission
             // reference file by absolute path since file system is un-sandboxed
             fs.root.getFile(filename, {create: true},
                 function (fileEntry) {
                     fileEntry.createWriter(function (writer) {
                         writer.onwriteend = function (evt) {
				console.log("write success");
                         };
			 console.log("before write " + filename);
			 var blob = new Blob([data], { type: "text/plain" });
                         writer.write(blob);
                    }, me.fileErrorHandler);
                 }, me.fileErrorHandler);
             };
	     window.requestFileSystem(window.PERSISTENT, 5*1024*1024,writeFileSystem);

 Thanks

DM

------------
"The shortest answer is doing." - Jacula Prudentum
My app: Cashalyst
Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: HTML 5 FileWriter size limit

Have you seen this link?

http://www.html5rocks.com/en/tutorials/file/filesystem/

 

Has tons of info on how to implement his.  Also it does mention that chrome is the only browser to do this.  Although we all know that Blackberry browser also has this functionality.

 

http://caniuse.com/#search=filesystem

 

However it also says that there i a limit per browser.  Maybe someone from RIM can confirm what is the limit on the BB browser for filewriter...

If it helped you, click like. :smileyhappy:
Contributor
DigitalMaestro
Posts: 38
Registered: ‎03-07-2012
My Device: Dev Alpha B, Playbook 16GB, Z10 LE

Re: HTML 5 FileWriter size limit

Yes, I've seen those links, thanks.  In fact I used the HTML5 Rocks link to implement the file writing.  The BB10 browser implementation does not appear to have an explicit way to request quota from the user.  In any case I do not get error result codes when trying to write files (which one would expect if one were over quota).  From what I have seen quota limits are usually 5mb.  A limit of 448kb, which is what I am experiencing in my code, would be absurdly low.  I am either doing something wrong or there is a bug in the BB10 webkit implementation.

 

Cheers

DM

------------
"The shortest answer is doing." - Jacula Prudentum
My app: Cashalyst
Contributor
DigitalMaestro
Posts: 38
Registered: ‎03-07-2012
My Device: Dev Alpha B, Playbook 16GB, Z10 LE

Re: HTML 5 FileWriter size limit

I have done a bit more research and testing on this and I believe that I have now resolved the issue.  The root cause is that when the FileWriter overwrites an existing file it does not automatically reduce the file size if the size of the data written is less than the size of the original file.  This behaviour is by design I believe because I can see this being very useful under certain scenarios.  The solution in my case was to truncate the file prior to writing to it.  With respect to my original issue of a file size limit, I believe I was getting confused after testing the same output multiple times.  The improved code, in case it helps anyone, is below:

 

	blackberry.io.sandbox = false;
	    
	    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
	    var writeFileSystem = function (fs) {
             fs.root.getFile(filename, {create: true},
                 function (fileEntry) {
                     fileEntry.createWriter(function (writer) {
                     	writer.onwriteend = function(evt){
	                         writer.onwriteend = function (evt) {
				        console.log("write success");
	                         };
	                         writer.onerror = function(err) {
	                         	console.log("write failed ", err);
	                         }
				 var blob = new Blob([data],{type: 'text/plain'});
	                         writer.write(blob);
                     	}
                     	writer.seek(0);
                     	writer.truncate(0);
                    }, me.fileErrorHandler);
                 }, me.fileErrorHandler);
        };
	window.requestFileSystem(window.PERSISTENT, 5*1024*1024,writeFileSystem);

 Cheers

DM

------------
"The shortest answer is doing." - Jacula Prudentum
My app: Cashalyst
Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: HTML 5 FileWriter size limit

Tx for sharing.  This will be usefull going forward. :smileyhappy:

If it helped you, click like. :smileyhappy: