尝试使用Filetransfer phonegap下载Android文件,但由于下载错误(错误代码= 1,即FileError.NOT_FOUND_ERR),文件无法下载。
以下是代码:(其中url为http://samplepdf.com/sample.pdf)
以下是代码:(其中url为http://samplepdf.com/sample.pdf)
function downloadImage(url,fileName){
var fileTransfer = new FileTransfer();
fileTransfer.download(
url,
window.rootFS.fullPath+ "/" + fileName,
function(entry) {
alert("download complete: " + entry.fullPath);
},
function(error) {
alert("download error"+JSON.stringify(error));
}
);
}
检查了window.rootFS.fullPath + "/" + fileName,得到/mnt/sdcard/myFileName。尝试仅使用目录名(即/mnt/sdcard)更改fullpath,但仍然无法使用,出现相同的错误。
错误是文件不存在,但实际上它存在。(您可以通过访问上面的samplepdf链接来查看。)
此外,我已经在android的res/xml/中允许了所有url访问。
奇怪的是,JSON错误对象字符串给出HTTP状态为200(成功)。
有人能建议问题可能出在哪里,或者解决它吗:)?