npm i --save @azaschka/nativescript-file-downloader
- 版本:1.5.5
- GitHub: https://github.com/tobydeh/nativescript-download-progress
- NPM: https://npmjs.net.cn/package/%40azaschka%2Fnativescript-file-downloader
- 下载
- 昨天:19
- 上周:19
- 上个月:28
nativescript-download-progress

简介
此插件允许您下载大文件并提供进度更新。
Nativescripts http.getFile 方法将数据存储在内存中,这可能导致内存不足异常,并且不提供进度更新。
安装
tns plugin add nativescript-download-progress
示例
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);
});
传递请求头
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);
}
许可证
Apache 许可证版本 2.0,2004 年 1 月