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
jeroen13
Posts: 39
Registered: ‎02-07-2012
My Device: Blackberry curve 8520 // Blackberry playbook 64GB
My Carrier: Vodafone

Downloading, Saving and Opening File on Playbook

[ Edited ]

hi all, im look for a way of 

 

-Downloading a File (From a website), Saving it to the /documents folder and then opening that file.

 

i tried everything, but i havent figured out how i can do it ....

 

Any scripts? (with buttons)

 

Thanks in advance

 

Please dont link me to those developer.blackberry.com pages.. those codes... i just dont get it

 

 

 

Edit: this is what i have so far (It downloads and stores the file but you CAN'T open it with the File browser "file is damaged or not opened correctly")

<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 = 'http://bbsample.comze.com/download.doc';
		var filePath = blackberry.io.dir.appDirs.shared.documents.path + '/download.doc';
		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>
<script type="text/javascript">
var filePath = blackberry.io.dir.appDirs.shared.documents.path + '/download.doc';

function openFile() {

if (blackberry.io.file.exists(filePath)) {

//file exists so load its contents

blackberry.io.file.readFile(filePath, readFile);

alert(“File successfully loaded”);

} else {

//file does not exist so display that to the user

alert(“File does not exist”);

}

}

function readFile(filePath, data) {

//retrieves the text stored in the file

var temp = blackberry.utils.blobToString(data);

}
</script>        
    <button onClick="saveFile()">Save</button> <button onClick="openFile()">Open File</button>

 

 

 

Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 795
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: Downloading, Saving and Opening File on Playbook

There is sample code and a description of what to do here: http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/stringToblog-save-image-problem/...

 

And a full working sample here: https://github.com/timwindsor/EnyoJS-on-BlackBerry/tree/master/Enyo-2.0-WebWorksExtensions

 

It requires a patch to be added to your WebWorks SDK which has instructions for patching here: http://devblog.blackberry.com/2012/04/webworks-sdk-extensions-patching/

Tim Windsor
Application Development Advisor II
Please use plain text.
Developer
asiayeah
Posts: 118
Registered: ‎11-05-2011
My Device: Z10, Bold 9900
My Carrier: Smartone

Re: Downloading, Saving and Opening File on Playbook

I also saw there's a WebWorks extension for PlayBook tablet in https://github.com/blackberry/WebWorks-Community-APIs/tree/master/Tablet/UploadDownload

 

Would that one be more efficient for downloading binary files to a local disk?

 

Thanks.

Please use plain text.
Developer
Developer
LBP
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: Downloading, Saving and Opening File on Playbook

Hi

 

this is really what you want to use to download remote files to the PlayBook. I created an app in the past and was looking for the same solution and got a requested link to this extension. Follow the info-page to set up this extension and try it, it will really help in saving files to the PlayBook!

 

Regards.


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 795
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: Downloading, Saving and Opening File on Playbook

Yes, I'd recommend going with that extension first as it looks very easy to use. 

Tim Windsor
Application Development Advisor II
Please use plain text.
Developer
asiayeah
Posts: 118
Registered: ‎11-05-2011
My Device: Z10, Bold 9900
My Carrier: Smartone

Re: Downloading, Saving and Opening File on Playbook

I've tried the UploadDownload extension, however, it seems it can only support downloading 1 file at a time. Is it the case?

 

I've logged an issue at https://github.com/blackberry/WebWorks-Community-APIs/issues/98

Please use plain text.