Background Upload plugin for the NativeScript framework
TypeScript JavaScript HTML Shell CSS
Clone or download
tgpetrov Merge pull request #163 from NativeScript/sis0k0/ng-wp-build-deps
chore: replace @angular-devkit/core with @ngtools/webpack
Latest commit 3d06d2a Jul 10, 2018

README.md

Background Upload NativeScript plugin Build Status

A cross platform plugin for the NativeScript framework, that provides background upload for iOS and Android.

There is a stock NativeScript http module that can handle GET/POST requests that work with strings and JSONs. It however comes short in features when it comes to really large files.

The plugin uses NSURLSession with background session configuration for iOS; and for android - the alexbbb/android-upload-service that implements an IntentService.

Installation

tns plugin add nativescript-background-http

Usage

The below attached code snippets demonstrate how to use nativescript-background-http, while uploading single or multiple files.

uploadFile

uploading sigle file to the service

import * as bghttp from "nativescript-background-http";
var session = bghttp.session("image-upload");

.....
var request = {
		url: url,
		method: "POST",
		headers: {
			"Content-Type": "application/octet-stream",
			"File-Name": name
		},
		description: description
	};

	if (should_fail) {
		request.headers["Should-Fail"] = true;
	}

let task: bghttp.Task;
task = session.uploadFile(file, request);

multipartUpload

uploading multiple files while using nativescript-background-http. Make sure all params sent to multipartUpload have string values.

import * as bghttp from "nativescript-background-http";
var session = bghttp.session("image-upload");

.....
var request = {
		url: url,
		method: "POST",
		headers: {
			"Content-Type": "application/octet-stream",
			"File-Name": name
		},
		description: description
	};

	if (should_fail) {
		request.headers["Should-Fail"] = true;
	}

let task: bghttp.Task;
var params = [
			{ name: "test", value: "value" },
			{ name: "fileToUpload", filename: file, mimeType: 'image/jpeg' }
		];
task = session.multipartUpload(params, request);

To get advantage of the demo apps and test the functionality, you will have to start the server from demo-server folder part of the repository. To do so, execute cd demo-server && npm run start command in a terminal.

Contribute

We love PRs! Check out the contributing guidelines. If you want to contribute, but you are not sure where to start - look for issues labeled help wanted.

Get Help

Please, use github issues strictly for reporting bugs or requesting features. For general questions and support, check out the NativeScript community forum or ask our experts in NativeScript community Slack channel.

License

Apache License Version 2.0, January 2004