我有一个cordova应用程序,具有下载pdf文档和存储在cordova文件位置的功能。任何帮助或建议将不胜感激。
cordova版本:6.4.0
插件版本:cordova-plugin-file-transfer 1.4.0“文件传输”
平台:ios 10.2.1
url返回错误代码2:
file:/// var / mobile / Containers / Data / Application / 4FC21BCF-DFC4-4A85-BA17-1F9C300B45F3 / Documents / 4092477_Unlock Scanner Guide.pdf
这是功能:
function downloadAsset(err) {
isDownloaded = true;
window.resolveLocalFileSystemURL(cordova.file.documentsDirectory, function (dirEntry) {
console.log('file system open: ', dirEntry);
target = dirEntry.toURL();
target = target + fileName;
var fileTransfer = new FileTransfer();
console.log("About to start transfer");
console.log(target+fileName);
fileTransfer.download(assetURL, target,
function(entry) {
console.log("Success!");
appStart(target);
},
function(e) {
console.log("Error");
console.dir(e);
});
}, resOnError);
}
答案 0 :(得分:1)
var url = "YOUR URL";
var dest = "YOUR DEST FILE PATH";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
fs.root.getFile(dest, { create: true, exclusive: false }, function (fileEntry) {
var fileTransfer = new FileTransfer();
fileTransfer.download(
encodeURI(url),
fileEntry.toURL(),
function(entry){
//DOWNLOAD OK
},
function(err){
//ERROR
},
null,
{}
);
}, function(err){
//ERROR
});
}, function(err){
//ERROR
});