【发布时间】:2017-04-28 18:36:51
【问题描述】:
我正在使用 Nativescript/Angular 2 构建一个应用程序
我希望能够从 URL 下载文件并将其保存到设备中普通用户可以毫无问题地找到它的位置。我相信在iOS 和Android 上下载将是最好的地方。如果我错了,请纠正我。
文件可以是任何文件类型,而不仅仅是图像。所以主要是spreadsheet、word document、pdf、png、jpg等
我已经在网上和文档中进行了搜索。该文档描述了一种名为getFile 的方法,该方法获取文件并将其保存到您的设备中。
我在我的代码中实现了如下:
download (id) {
console.log('Download Started');
getFile("https://raw.githubusercontent.com/NativeScript/NativeScript/master/apps/tests/logo.png").then(function (r) {
console.log(r.path);
}, function (e) {
//// Argument (e) is Error!
});
}
这样做的问题是它会将其保存到非用户可访问的位置,例如:
/data/user/0/com.myapp.example/files/logo.png
更新:
我也试过直接指定路径:
fs.knownFolders.documents();
但是,此方法获取用户或外部应用程序无法访问的当前应用程序的文档文件夹
【问题讨论】:
标签: http angular typescript nativescript angular2-nativescript