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
Posts: 116
Registered: ‎03-08-2011
My Device: Not Specified

blackberry.io.file.saveFile() not working on Playbook

I'm trying a simple script just to get it to work. It won't create the blob or save a file. Here's my code:

 

Part of my Config.xml

   
  <rim:permissions>
    <rim:permit>access_shared</rim:permit> 
  	<access subdomains="true" uri="file:///accounts/1000/shared/downloads/"/> 
  </rim:permissions> 
  <feature id="blackberry.app" version="1.0.0" />
  <feature id="blackberry.app.event"  required="true" version="1.0.0.0" /> 
    <feature id="blackberry.invoke" required="true" version="1.0.0"/>
    <feature id="blackberry.invoke.BrowserArguments" required="true" version="1.0.0"/>
    <feature id="blackberry.identity" required="true" version="1.0.0"/>
    <feature id="blackberry.ui.dialog" required="true" version="1.0.0"/>
  <feature id="blackberry.io.dir" required="true" version="1.0.0.0"/>
  <feature id="blackberry.io.file" required="true" version="1.0.0.0"/>
  <feature id="blackberry.utils"/>

 

HTML code:

<div id="log"></div>
		
<script type="text/javascript">

function log(text) {
	"use strict";
	var div = document.createElement("div");
	div.innerHTML = text;
	document.querySelector("#log").appendChild(div);
}
			
function saveFile() {
	try{
		log("start");		   
		var filePath = 'file:///accounts/1000/shared/downloads/test.txt';
		var textarea = 'testing here333sdsds';
		log("start create blob");		
		blob = blackberry.utils.stringToBlob(textarea);
		log("blob created");
		log("file save begin");
		blackberry.io.file.saveFile(filePath, blob);
		log("file saved");
	}catch(err){
		log("Error description: " + err.message);
	}
}
</script>
        
    <button onClick="saveFile()">Save</button>

 

The error msg in ripple says: Error description: Cannot read property 'children' of undefined

Ripple crashes at saveFile.

 

The error msg when testing on the PB says: Error description: 'undefined' is not a function

Playbook crashes at stringToBlob.

 

What am I doing wrong?

 

Thanks

 

 

 

 

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: blackberry.io.file.saveFile() not working on Playbook

There are a couple things that seem to be causing trouble, mostly for Ripple.

 

This line in the config seems to cause it to b unable to read your config.xml, but doesn't seem to affect the app otherwise. It's not necessary and should be left out:

 

<access subdomains="true" uri="file:///accounts/1000/shared/downloads/"/> 

The other part which is the more serious issue is the actual file path that you are using. It's the direct one that you are attempting to use but it's not supported by Ripple, and obviously appears to have trouble on the PlayBook in the version you are testing with. It's not causing trouble in 2.0.1 though, which is good. A simple fix should resolve it for all, though.

 

Instead of using the direct file path, use the path like this:

 

//var filePath = 'file:///accounts/1000/shared/downloads/test.txt';
var filePath = blackberry.io.dir.appDirs.shared.downloads.path + '/test.txt';

 It's a more proper way of accessing the shared location in the sandbox environment anyway.

Tim Windsor
Open Source Technical Lead
Developer
Posts: 116
Registered: ‎03-08-2011
My Device: Not Specified

Re: blackberry.io.file.saveFile() not working on Playbook

Hi Tim,

 

Thanks for the response. I made the 2 changes you've outlined above. The script works in ripple (but of course I can't see if a file was saved there) but still generates the same error on the Playbook (OS 2.0.0.7971).

The error seems to be generated when creating the blob:

blob = blackberry.utils.stringToBlob(textarea);

 And the error msg is 'undefined' is not a function

 

1) Any ideas why the blob won't create? I assume it's necessary to create the blob.

2) Is there a release date for OS2.0.1? I'm sure there is a way to check to see what OS version is being used by the user. I'll have to look that up.

 

Thanks.

 

 

 

 

 

 

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: blackberry.io.file.saveFile() not working on Playbook

It's really odd. It seems like your build is not pulling in blackberry.utils for some reason. Do you want to try compiling with the -s option so that it creates the source directory so you can check for the extension?

 

You could also use WebInspector with a breakpoint to see if the extension is there while running.

 

I've attached my sample if you want to try it out and compare it.

Tim Windsor
Open Source Technical Lead
Developer
Posts: 116
Registered: ‎03-08-2011
My Device: Not Specified

Re: blackberry.io.file.saveFile() not working on Playbook

I downloaded and tried both zips that you sent, thanks. Here are my results:

 

The zipped BAR, once installed (after I changed the manifest.mf info) worked as it should. BLOB and saveFile worked properly and the new file appeared. So I then zipped and compiled the other files you sent without making any changes, and the same BLOB error above occurred.  I added the -s option to see the source files and the Utilities.as file is located in the \src\blackberry\utils folder. It contains:

 

/*
* Copyright 2010-2011 Research In Motion Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package blackberry.utils
{
	import webworks.extension.DefaultExtension;
	
	public class Utilities extends DefaultExtension {
		public function Utilities() {
			super();
		}
		
		override public function getFeatureList():Array {
			return [ "blackberry.utils" ];
		}
	}
}

 

Not sure if this is correct or not, so I unzipped your BAR file to see what the difference is. My utilities_ns.js file in the \bin\air\WebWorksApplicationSharedJsRepository0\blackberry_utils_Utilities\js\common folder is missing the function:

 

	
	function Utils(disp) {
		this.constructor.prototype.blobToString = function(blob, encoding)
								{ return disp.blobToString(blob, encoding); };
		this.constructor.prototype.stringToBlob = function(s, encoding)
								{ return disp.stringToBlob(s, encoding); };		
	}

 

Not sure if anything else is missing but the error is definitely a compilation error. I have the latest BBWP installed so I'm not really sure how I would go about fixing this. When I get a chance I'll try unistalling the BBWp and reinstalling it. Maybe that'll fix it. Smiley Frustrated

 

Thanks for your help. If I find the solution, I'll post it here for others to see.

 

 

 

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: blackberry.io.file.saveFile() not working on Playbook

That's very weird. Seems like the install is botched. Try a reinstall and if that doesn't work, I posted an article on patching your webworks today on the devblog.
Tim Windsor
Open Source Technical Lead
Developer
Posts: 116
Registered: ‎03-08-2011
My Device: Not Specified

Re: blackberry.io.file.saveFile() not working on Playbook

[ Edited ]

Tried unistalling and reinstalling. Same issue when compiling. I am downloading the BBWP (tablet OS) from here: https://bdsc.webapps.blackberry.com/html5/download/sdk where it says it's version 2.2 but when I install it, in windows control panel installed programs it tells me that version 2.0.0.4 is installed. Is the wrong version up there for download? Maybe an older version? Could that be the problem? I didn't try updating my air version. I have air 3.1 installed.

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: blackberry.io.file.saveFile() not working on Playbook

I'm not sure how this is happening. I downloaded the SDK from there just now and installed it. The version is 2.2.0.5 and it's got the full Utilities.as file. Do you want to try again, and maybe clear your browser cache just in case?

Tim Windsor
Open Source Technical Lead
Developer
Posts: 116
Registered: ‎03-08-2011
My Device: Not Specified

Re: blackberry.io.file.saveFile() not working on Playbook

Tried again. When it's installing, it says 2.2.0.5. After it's installed, in Windows7 Unistall a program list, the version number shows 2.0.0.4. I will try downloading the package from another machine.