如何使用Ionic Framework将文件下载到Download的目录?
问题描述:
我正在尝试使用 ngCordova
,但 cordova.file.documentsDirectory
属性为 null
。
I'm trying with ngCordova
but the cordova.file.documentsDirectory
property is null
.
我还尝试将 ngCordova
的使用与 requestFileSystem ,但是,该文件仍未保存在下载中。
I have also tried combining the use of ngCordova
with requestFileSystem
, but still, the file is not saved in the "Download's".
我的代码示例:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(directory) {
var fileTransfer = new FileTransfer();
fileTransfer.download(
encodeURI("http://example.com/sample.pdf"),
directory.root.nativeURL + 'sample.pdf',
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false
);
}, function(err){console.error(err)});
谢谢。
答
cordova.file.externalRootDirectory +'/ Download /'+'sample.pdf'
而不是 directory.root.nativeURL + 'sample.pdf'