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
Developer
confinedspace
Posts: 40
Registered: ‎04-16-2010
My Carrier: na
Accepted Solution

Unable to Save File (OS6)

[ Edited ]

UPDATE: Just found out that documentToBlob is only supported in OS5. How do I do the same in OS6?

 

http://www.blackberry.com/developers/docs/webworks/api/blackberry.utils.html#.documentToBlob

 

 


 

I wrote an app several months ago which has been working fine with OS5. But it does not work with OS6. Here's a simple example of creating a file, which the app needs to do:

 

config.xml

 

<?xml version="1.0" encoding="utf-8" ?>
    <widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:rim="http://www.blackberry.com/ns/widgets"
        rim:header="RIM-Widget:rim/widget"
        version="1.0.0">
     <name>File Test</name>
    <description>Testing file</description>
     <author href="http://www.example.com/" rim:copyright="no copyright" email="info@example.com">Example</author>
     <license href="" />
     <feature id="blackberry.utils" version="1.0.0"/> 
     <feature id="blackberry.io.dir" version="1.0.0"/>
     <feature id="blackberry.io.file" version="1.0.0"/>
     <feature id="blackberry.ui.menu" version="1.0.0"/>
     <feature id="blackberry.system.event" version="1.0.0"/>
     <feature id="blackberry.invoke" version="1.0.0"/>
    <feature id="blackberry.invoke.MapsArguments" version="1.0.0"/>
    <content src="test.html" />
</widget>

 

test.html

 

<html>
<head>
    <title>Test</title>
    <meta name="viewport" id="viewport" content="initial-scale=1.0,user-scalable=no" />
    <script src="scripts/test.js" type="text/javascript"></script>
</head>
<body onload="loadTest();">
	testing
</body>
</html>

 

scripts/test.js

 

function loadTest(){
	alert("start");
	var filePath = "file:///store/home/user/appTest.xml";
	var xmlString = "<test>test_data</test>";
	var parser = new DOMParser();
	var doc = parser.parseFromString(xmlString, "text/xml");
    try{
        var blobData = blackberry.utils.documentToBlob(doc);
        blackberry.io.file.saveFile(filePath, blobData);
        alert("file saved");
    } catch(e) {
    	alert("unable to save file: "+e.message);
    }
    if(blackberry.io.file.exists(filePath))
    	alert("file exists");
    else
    	alert("file cannot be found");
    alert("end");
}

 

OS6 simulator (6.0.0.337) output:

  • start
  • unable to save file: undefined
  • file cannot be found
  • end

Any idea why it doesn't work?

Please use plain text.
BlackBerry Development Advisor
jeffheifetz
Posts: 518
Registered: ‎07-18-2011
My Carrier: Rogers

Re: Unable to Save File (OS6)

Can you just use stringToBlob?

 

http://www.blackberry.com/developers/docs/webworks/api/blackberry.utils.html#.stringToBlob

 



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Please use plain text.
Contributor
hababut
Posts: 41
Registered: ‎07-21-2011
My Carrier: Rogers

Re: Unable to Save File (OS6)

documentToBlob has been deprecated in 6.0, it's only available in 5.0.

----------------------------------------------------------------------------------------------
I kode for cudos! Or was it the other way around?
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,702
Registered: ‎10-16-2008
My Carrier: Rogers

Re: Unable to Save File (OS6)

Since the document is a JavaScript object you should be able to do a toString() on it.

 

So you could do something like the following pseudo code

 

var foo = blackberry.utils.stringToBlob(document.toString());

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
confinedspace
Posts: 40
Registered: ‎04-16-2010
My Carrier: na

Re: Unable to Save File (OS6)

Thanks for the reply. I can now save a file, but it's empty in both OS5 & OS6. Here's my updated .js file with your suggestions (the config.xml, etc is same as my first post):

 

function loadTest(){
    alert("start");
    var filePath = "file:///store/home/user/appTest.xml";
    var xmlString = "<test>test_data</test>";
    var parser = new DOMParser();
    var doc = parser.parseFromString(xmlString, "text/xml");
    var blobData = blackberry.utils.stringToBlob(doc.toString());
    try{
        blackberry.io.file.saveFile(filePath, blobData);
        alert("file saved");
    } catch(e) {
        alert("unable to save file: "+e.message);
    }
    if(blackberry.io.file.exists(filePath))
        alert("file exists");
    else
        alert("file cannot be found");
    alert("end");
}

 

Has anyone got a working copy of saving an XML document on OS6 or OS7?!

 

Thanks for your help.

Please use plain text.
BlackBerry Development Advisor
jeffheifetz
Posts: 518
Registered: ‎07-18-2011
My Carrier: Rogers

Re: Unable to Save File (OS6)

Hi 

 



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Please use plain text.
Developer
confinedspace
Posts: 40
Registered: ‎04-16-2010
My Carrier: na

Re: Unable to Save File (OS6)

Thanks jeffheifetz.

 

I'm following what has been recommended by the BB documentation: https://bdsc.webapps.blackberry.com/html5/apis/blackberry.utils.html#.documentToBlob - but it doesn't work.

 

The documentation to save a file doesn't work either as it uses a depriciated function (documentToBlob): https://bdsc.webapps.blackberry.com/html5/apis/blackberry.io.file.html#.saveFile

 

Is there an example anywhere which shows how to save an XML document on OS6?

Please use plain text.
Developer
confinedspace
Posts: 40
Registered: ‎04-16-2010
My Carrier: na

Re: Unable to Save File (OS6)

I couldn't find a solution to this, nor could anyone help. I had to rewrite my application to store data in a database instead of an XML file.

Please use plain text.