@azaschka/nativescript-file-downloader
TypeScript icon, indicating that this package has built-in type declarations

1.5.5 • Public • Published

nativescript-download-progress apple android

npm version

Introduction

This plugin allows you to download large files and provides progress updates.

Nativescripts http.getFile method stores the data in memory which can cause out of memory exceptions and doesn't provide progress updates.

Installation

tns plugin add nativescript-download-progress

Examples

import { DownloadProgress } from "nativescript-download-progress";

const dp = new DownloadProgress();
dp.setProgressCallback((progress, url, destination) => {
  console.log("Progress:", progress, "URL:", url, "Destination", destination);
});
dp.downloadFile("http://ipv4.download.thinkbroadband.com/20MB.zip")
  .then((file) => {
    console.log("Success", file);
  })
  .catch((error) => {
    console.log("Error", error);
  });

Passing request headers

import { DownloadProgress } from "nativescript-download-progress";

const dp = new DownloadProgress();
dp.setProgressCallback((progress, url, destination) => {
  console.log("Progress:", progress, "URL:", url, "Destination", destination);
});
const url = "http://ipv4.download.thinkbroadband.com/20MB.zip";
const destinationPath = "some/path/to/file.zip";
const requestOptions: RequestOptions = {
  method: "GET",
  headers: {
    Range: "bytes=-",
  },
};
dp.downloadFile(url, requestOptions, destinationPath)
  .then((file) => {
    console.log("Success", file);
  })
  .catch((error) => {
    console.log("Error", error);
  });

Async / Await

import { DownloadProgress } from "nativescript-download-progress";

const dp = new DownloadProgress();
dp.setProgressCallback((progress, url, destination) => {
  console.log("Progress:", progress, "URL:", url, "Destination", destination);
});
try {
  const f = await downloadFile(
    "http://ipv4.download.thinkbroadband.com/20MB.zip"
  );
} catch (e) {
  console.log("Error", error);
}

License

Apache License Version 2.0, January 2004

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.5.51latest

Version History

VersionDownloads (Last 7 Days)Published
1.5.51
1.5.40
1.5.30
1.5.20
1.5.10
1.5.00

Package Sidebar

Install

npm i @azaschka/nativescript-file-downloader

Weekly Downloads

1

Version

1.5.5

License

Apache-2.0

Unpacked Size

32.8 kB

Total Files

14

Last publish

Collaborators

  • azaschka