Giter Site home page Giter Site logo

nativescript-background-http's Introduction

Background Upload plugin for the NativeScript framework

How to use the plugin, see: source/README.md

iOS

The iOS API is implemented in JavaScript.

Android

The minimum supported API level is 18 and the background file upload is handled by the android-upload-service Open-Source library.

Examples

To run the example open a terminal and run in the root of the repo:

npm install

This will start the server included in examples/www:

npm start

Open a second terminal, again at the root of the repo. This will create a link from the nativescript-background-http to the examples/SimpleBackgroundHttp's node_modules so you can build and run the plugin from source:

npm run link

To compile the TypeScript of the plugin:

npm run tsc

Then to run the app:

tns run android --path examples/SimpleBackgroundHttp

Usage

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

For further help review the (SimpleBackgroundHttp)[https://github.com/NativeScript/nativescript-background-http/tree/master/examples] application.

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);

nativescript-background-http's People

Contributors

panayotcankov avatar nickiliev avatar ignaciolarranaga avatar hdeshev avatar tjzfg avatar romulowspp avatar sud80 avatar daxito avatar friedolinfoerder avatar nathanaela avatar hamorphis avatar

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.