Giter Site home page Giter Site logo

dbotelho / blackberry.io.filetransfer Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 264 KB

Blackberry Javascript Extension that allow you to Download Files in a Webworks project

Home Page: http://blog.dbotelho.com/2012/06/blackberry-webworks-javascript-extension-to-allow-file-downloads

Java 100.00%

blackberry.io.filetransfer's Introduction

# File Transfer for Blackberry Webworks

This is an Javascript Extension for Blackberry Webworks projects that allows you to download files within your Blackberry Webworks widget.

## How to install

1. Download the file https://github.com/downloads/dbotelho/blackberry.io.filetransfer/blackberry.io.filetransfer.jar and add it to your "ext" folder in your Webworks project;
2. Then go to your "config.xml" file and add the following lines:

`` <feature id="blackberry.io.filetransfer" required="false" version="1.0.0"/>``

``<access subdomains="false" uri="file:///"/>``
    

## API

### Method:

    blackberry.io.filetransfer.download(arguments);
    
### Arguments (Array):

- url (required): Is the download url. ex: "https://www.google.com/images/srpr/logo3w.png"
- dest (required): Is the local file location. ex:"file:///store/home/user/logo/logo.png"
- type (optional): Can be 'POST' or 'GET' (default: 'GET')
- success (optional): Is a Javascript function that is called after the download is complete
- error(optional): Is a Javascript function that is called if the download fails for some reason
- headers (optional): For this version the headers only allows you to set the "Authorization" and/or "Content-Type", but if you need more support please let me know.

## Example 1: Download the google logo and notify when it's done

    <script language="javascript" type="text/javascript">

	// Here whe need to create the local folder, if it doesn't exist already
	if (!blackberry.io.dir.exists("file:///store/home/user/logos/")) {
		blackberry.io.dir
				.createNewDir("file:///store/home/user/logos/");
	}
	
	// Download the file
	blackberry.io.filetransfer.download({
		url: "https://www.google.com/images/srpr/logo3w.png", 	// the image url
		type : 'GET',											// explicitly setting method type to 'GET'
		dest: "file:///store/home/user/logos/GoogleLogo.png",	// the local file
		success : function(data){								// The function called after the file is downloaded
			alert('success');
		},
		error : function(data){										// The function called if something fails
			alert('error:'+data);
		}
	})
    </script>

## Example 2: Download the google logo with HTTP Basic Authentication

    <script language="javascript" type="text/javascript">
	function make_base_auth(user, password) {
	  var tok = user + ':' + pass;
	  var hash = Base64.encode(tok);
	  return "Basic " + hash;
	}

	// Here whe need to create the local folder, if it doesn't exist already
	if (!blackberry.io.dir.exists("file:///store/home/user/logos/")) {
		blackberry.io.dir
				.createNewDir("file:///store/home/user/logos/");
	}
	
	// Download the file
	blackberry.io.filetransfer.download({
		url: "https://www.google.com/images/srpr/logo3w.png", 	// the image url
		type : 'GET',											// explicitly setting method type to 'GET'
		headers:{
			Authorization: make_base_auth("my_username","my_password"),
			"Content-Type": "application/x-www-form-urlencoded"
		},
		dest: "file:///store/home/user/logos/GoogleLogo.png",	// the local file
		success : function(data){								// The function called after the file is downloaded
			alert('success');
		},
		error : function(data){										// The function called if something fails
			alert('error:'+data);
		}
	})
    </script>

blackberry.io.filetransfer's People

Contributors

dbotelho avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

engti ganesh1987

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.