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

How to create an application to Download and Upload files

by Retired on ‎01-20-2012 04:09 PM (5,946 Views)

What Is It?

This sample demonstrates how you can transfer files from a server to the device utilizing the BlackBerry WebWorks SDK


Applies To

  • BlackBerry® Tablet OS
  • BlackBerry® WebWorks™ SDK for Tablet OS


Configuring Your Extension

Copy library.xml, the src, and the js folder into the webworks.io.filetransfer folder such that ext directory looks like below.




To make use of extensions, you must modify your configuration files allow access to the custom feature.


In config.xml


<feature id="webworks.io.fileTransfer"/>
<feature id="blackberry.io.dir"/>

Since your application will be accessing the PlayBook's filesystem, you will need to grant permission for your application to manipulate the media directories of the filesystem. 


In blackberry-tablet.xml




Getting Started

Download the sample code from Github, build it using BlackBerry WebWorks SDK and install the sample app on a BlackBerry Tablet OS simulator.




How It Works

 Using the webworks.io.fileTransfer WebWorks JavaScript API allows you to transfer data/media content between a web server and device. 


In short your code will include the following:


var ft = blackberry.io.fileTransfer;

// progressInterval - Default set to 0. The frequency, in milliseconds for the callback
// the username and password for an operation to the authentication
// Default to 30000. The timeout for operation in milliseconds.

var options = {'progressInterval': 1000,
               'username' : 'foo',
               'password' : 'bar',
               'connectionTimeout' : 30000,
               'BESMaxSingeChunk' : 3279}
//For upload
//remotePath - The server address, along with the upload handler for managing the upload request
//localPath - The location of the file that you would like to transfer.

var remotePath = "";
var localPath = blackberry.io.dir.app.shared.camera.path + "/IMG_00000001.jpg";
ft.upload(remotePath, localPath, onProgress, onError, options);

//For Download
//remotePath - The server address, along with the path to the file name you would like to transfer.
//localPath - The location of the folder you would like to download the file to.

var remotePath = "";
var localPath = blackberry.io.dir.app.shared.download.path + "/";
ft.download(remotePath, localPath, onProgress, onError, options);


In order for a successful upload, your server must be able to successfully handle an upload request:


The following php script upload.php helps handle server upload requests ( This script requires PHP to be installed on the server):


<title>Process Uploaded File</title>
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['file']['name']);

if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['file']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";

More Info

by Developer
on ‎02-11-2012 03:38 AM

You need to compile this example with WebWorks SDK for TabletOS, compiling it with will fail with errors.

Users Online
Currently online: 40 members 1,877 guests
Please welcome our newest community members: