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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Web and WebWorks Development

Reply
Contributor
_MARIO_
Posts: 16
Registered: ‎04-26-2011
My Carrier: Vodafone Spain

Writing files to SDcard from WebWorks

Hi,

 

I was wondering how to write files from a WebWorks app to the SD card or internal storage. Looking at the API there seems to be something that enables me to write to SD:

 

var filePath = "file:///SDCard/BlackBerry/Sample.txt";

var blob_data = blackberry.utils.documentToBlob(testData);

blackberry.io.file.saveFile(filePath, blob_data);

 

I also added the following to config.xml:

 

file:///SDCard/BlackBerry

 

Any idea why it isn't working?

 

By the way, what is a blob???

 

Regards

Please use plain text.
Developer
bnolan001
Posts: 93
Registered: ‎02-19-2011

Re: Writing files to SDcard from WebWorks

Did you figure this out yet? 

"Not to know what happened before you were born is to be forever a child." Marcus Tullius Cicero
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,693
Registered: ‎10-16-2008
My Carrier: Rogers

Re: Writing files to SDcard from WebWorks

Which OS version are you trying these calls?

 

BlackBerry 5.0, 6.0 or PlayBook?

 

BlackBerry 6.0 does not support the documentToBlob() function

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
bnolan001
Posts: 93
Registered: ‎02-19-2011

Re: Writing files to SDcard from WebWorks

I'm looking to do WebWorks for OS 6.0 and Playbook.  I just heard that at least for Playbook the feature will be available in mid-June.

"Not to know what happened before you were born is to be forever a child." Marcus Tullius Cicero
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,693
Registered: ‎10-16-2008
My Carrier: Rogers

Re: Writing files to SDcard from WebWorks

Yes, file I/O will be coming to WebWorks on PlayBook in a week or two.  However, documentToBlob and blobToDocument are only supported on BB5

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
bnolan001
Posts: 93
Registered: ‎02-19-2011

Re: Writing files to SDcard from WebWorks

Ok, so I was trying to access a file in the Playbook simulator but it didn't work.  The simulator is 1.0.1 and the SDK is the version released just a week or two ago. 

The code is below:

var filePath = blackberry.io.dir.appDirs.app.storage.path + "/favorites.txt";
	function onFileOpen(fullPath, blobData){
	      globalBlob = blobData;
	      alert(globalBlob);
	}
	alert(filePath);
	if (blackberry.io.file.exists(filePath)) {
	    try{
			blackberry.io.file.readFile(filePath,onFileOpen, true);
		}catch(e){
	      alert(e);
		}
	}
	else {
		var globalBlob = "TEST";
		blackberry.io.file.saveFile(filePath, globalBlob);
	}

 

"Not to know what happened before you were born is to be forever a child." Marcus Tullius Cicero
Please use plain text.
Developer
bnolan001
Posts: 93
Registered: ‎02-19-2011

Re: Writing files to SDcard from WebWorks

Looks like I found my answer:

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/BlackBerry-WebWorks-SDK-2-1-for-...

This feature isn't supported yet! 

 

"Not to know what happened before you were born is to be forever a child." Marcus Tullius Cicero
Please use plain text.