nativescript-tus-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

nativescript-tus-client

NativeScript plugin for TUS - Open Protocol for Resumable File Uploads. Uses TUSKit (iOS) and tus-android-client.

iOS Android
iOS demo Android demo

Installation

tns plugin add nativescript-tus-client

Usage

import { File, Folder, knownFolders } from "@nativescript/core";
import * as tus from "nativescript-tus-client";

// create a File reference
const file = File.fromPath(knownFolders.currentApp().path + 'assets/test_image.png');

// Create a new tus upload
var upload = new tus.Upload(file, {
    endpoint: "http://192.168.1.118:1080/files/",
    metadata: {
        filename: 'test_image.png',
        filetype: 'image/png'
    },
    headers: {
        Authorization: "Basic YWxhZGRpbjpvcGVuc2VzYW1l"
    },
    onError: function(error) {
        console.log("Failed because: " + error)
    },
    onProgress: function(bytesUploaded, bytesTotal) {
        var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
        console.log(bytesUploaded, bytesTotal, percentage + "%")
    },
    onSuccess: function() {
        console.log(`Download ${upload.file.name} from ${upload.url}` )
    }
})

// Start the upload
upload.start()

// Abort the upload
upload.abort()

API

nativesctipt-tus-plugin implements a very limited subset of the JS api. See the example above as it contains all the implemented API.

Test server

We included a tus test server. Remember to change the host in test-server/index.js:

const host = '192.168.1.118';

then:

cd test-server
npm run start

You will have to change the host in the demo app at demo/app/home/home-page.ts too.

Credits

A big thanks to coderReview for leading the way with his nativescript-tus-upload.

License

Apache License Version 2.0, January 2004

Dependents (0)

Package Sidebar

Install

npm i nativescript-tus-client

Weekly Downloads

1

Version

1.0.1

License

Apache-2.0

Unpacked Size

38.6 kB

Total Files

20

Last publish

Collaborators

  • tralves