【发布时间】:2014-10-21 07:47:56
【问题描述】:
我正在使用 Cordova 3.6.3,我想在 Android 中下载文件。我添加了有关文件和文件传输的所有权限,还添加了文件和文件传输插件。它给我错误代码:1 .它在内存上创建文件,但它的唯一名称.它是空的。问题出在哪里?
我查找了其他解决方案,但它不起作用。
var resimURL= "https://farm"+url.farm+".staticflickr.com/"+url.server+"/"+url.id+"_"+url.secret+"_b.jpg";
//alert("Download");
alert(resimURL);
var remoteFile =resimURL;
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem) {
fileSystem.root.getFile(localFileName, {create: true, exclusive: false},
function(fileEntry) {
var localPath = fileEntry.fullPath;
alert(localPath);
if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
localPath =fileSystem.root.toUrl()+localPath.substring(7);
alert(localPath);
}
var ft = new FileTransfer();
ft.download(remoteFile, localPath,
function(entry) {
alert("Download Complete");
},
fail);
},
fail);
},
fail);
function fail(error) {
alert("error"+error.code);
}
【问题讨论】: