Skip to content
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
..
Failed to load latest commit information.
ext
spec
README.md

README.md

File Transfer Information

NOTE: THIS IS A WORK IN PROGRESS

The File Transfer API will allow you to download and upload files from/to a server

Author: Maurice White Rosa Tse Tracy Li Dan Silivestru Ken Wallis

Tested On

Nothing yet...

Requires BlackBerry WebWorks SDK for Tablet OS v2.1 or higher

Have a problem with this extension? Log an Issue or contact the Authors above

How To Configure The Extension For Use

  1. Locate your BlackBerry WebWorks SDK for Tablet OS extensions directory using your File Explorer. Default path for Windows is C:\Program Files\Research In Motion\BlackBerry WebWorks SDK for \ext Default path for Mac is \Developer\SDKs\Research In Motion\BlackBerry WebWorks SDK for \ext

  2. Create a new webworks.io.filetransfer directory in the ext directory

  3. Download the source from this repository and unzip it to a location on your computer Tablet\UploadDownload

  4. Copy all files from the downloaded Tablet\UploadDownload\ext directory to your new ext\webworks.io.filetransfer directory

NOTE: Be sure to back-up this ext\webworks.io.filetransfer directory in your WebWorks SDK extensions directory before performing a WebWorks SDK upgrade. Simply copy it back into the ext directory after you have completed your SDK upgrade.

Required Feature ID

Whenever you use the below feature id in any of your WebWorks applications this extension will be loaded for use.

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

Summary

static void getRemoteFileSize(remotePath); // Returns the "Content-length" header value for the content at the remotePath.
static void download(remotePath, localPath, onProgress, onError, options); // Downloads the remote content to your localPath.
statid void upload(remotePath, localPath, onProgress, onError, options); // Uploads the local content to the remotePath - remotePath points to a server side script (e.g. a PHP file) that knows how to handle the upload, the script will have full control of the file's destination

Options

Integer progressInterval; // Default 0.  The frequency, in milliseconds, that the onProgress callback should be called with updates on the upload/download operation.  0 means onProgress will only be called upon completion ofthe operation.
optional String username; // the username required for an operation requiring authentication (not supported yet)
optional String password; // the password required for an operation requiring authentication (not supported yet)
optional connectionTimeout; // Default 30000.  The timeout for the operation, in milliseconds.
optional BESMaxSingleChunk; // ???

Status fields for onProgress callback Integer percent; // current completion percentage of the operation Integer totalFileSize; // in Bytes Integer numBytes; // Number of bytes retrieved/posted so far String localPath; String remotePath; //original request remote path String redirectPath; //actual path if content was on a redirect (for download only) String startTime; // dateTime String mimeType; // (for download only)

Code Example

<html>
  <head>
    <meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no" />
    <script type="text/javascript" >
        function doUpload() {
            var u = blackberry.io.fileTransfer;
            var options = {'progressInterval': 1000, 
                        'username':'foo', 
                        'password' : 'bar',
                        'connectionTimeout': 30000,
                        'BESMaxSingleChunk' : 3279}

            // Path could be one of http/https
            u.upload(remotePath, localPath, onProgress, onError, options);
        }

        function doDownload() {
            var d = blackberry.io.fileTransfer;

            // Check the file size
            var sizeInBytes = d.getRemoteFileSize('http://foo/bar.jpg');
            if (sizeInBytes > 27498274) {
                alert('hell no you are not downloading that thing!!');
                return;
            }

            // progressInterval = 0 means, let me know when it is done.  I.e. onProgress will act like a onSuccess... ;)
            var options = { 'progressInterval': 0, 
                        'username':'foo', 
                        'password' : 'bar',
                        'connectionTimeout': 30000,
                        'BESMaxSingleChunk' : 3279}
            // Path could be one of http/https
            d.download(remotePath, localPath, onProgress, onError, options);
        }

        // Error handler is something goes wrong during download/upload
        function onError(error) {
            alert("error code: " + error.code + "error.description: " + error.description);
        }

        // Event when data is being downloaded/uploaded
        function onProgress(status ) {
            if (console && console.log) {
                console.log("Percent complete: " + status.percent +
                    "\nTotal file size: " + status.totalFileSize +
                    "\nBytes downloaded: " + status.numBytes +
                    "\nLocal path: " + status.localPath +
                    "\nRemote path: " + status.remotePath +
                    "\nRedirect path: " + status.redirectPath + 
                    "\nStart time: " + (new Date(status.startTime)).toDateString() +
                    "\nMIME type: " + status.mimeType
                );
            }
        }
    </script>
  </head>
  <body >
    <button onclick="doDownload()">Download</button>
    <button onclick="doUpload();">Upload</button>
  </body>
</html>

<?xml version="1.0" encoding="utf-8"?>
<widget xmlns=" http://www.w3.org/ns/widgets"
    xmlns:rim="http://www.blackberry.com/ns/widgets"
    version="2.0.0.0">

    <name>Sample App</name>

    <description>
        A sample application to demonstrate some of the possibilities.
    </description>

    <content src="index.html"/>

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

    <access uri="*" subdomains="true"/>

</widget>
Something went wrong with that request. Please try again.