真令人恼火..几天前,我无法让 Cordova 文件传输插件与 PhoneGap 3.6.3 一起使用。现在看来,在我重写index.js之后,“未定义”错误的问题已经解决了。这是老问题:PhoneGap Build: Plugins not working (getting "undefined" errors) on Android
现在我遇到了一个新问题:Android 上的下载总是失败,并显示以下消息:
FileTransferError
body: null
code: 3
exception: null
http_status: 401
source: "http://www.hs-bremerhaven.de/fileadmin/images/logo.png"
target: "file:///data/data/de.testapp1374839/files/logo.png"
proto: Object
我已经尝试将这些功能标签添加到 config.xml 文件中:
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/network"/>
我提供了一个通配符来访问外部资源。
<access origin="*"/>
这是我更新的index.js:
var DR = {
initialize: function(){
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.getElementById('download').addEventListener('click', this.downloadFile, false);
},
onDeviceReady: function(){
},
downloadFile: function(){
console.log("Downloading...");
var $status = document.querySelector("#fileStatus");;
var assetURL = encodeURI("http://www.hs-bremerhaven.de/fileadmin/images/logo.png");
var fileName = "logo.png";
var DEV_PATH = cordova.file.dataDirectory;
var fullPath = DEV_PATH + fileName;
console.log("DEV_PATH " + DEV_PATH);
$status.innerHTML = "Checking for file";
window.resolveLocalFileSystemURL(fullPath, onFilePresent, downloadAsset);
function onFilePresent(){
console.log("File already there");
}
function downloadAsset() {
var fileTransfer = new FileTransfer();
console.log("Downloading: " + assetURL + " to " + fullPath);
fileTransfer.download(assetURL, fullPath,
function(entry) {
console.log("Success!");
onFilePresent();
},
function(err) {
console.log("Error");
$status.innerHTML = "Fehler.";
console.dir(err);
});
}
},
checkFile: function(){
//todo
}
};
任何帮助将不胜感激。
最佳答案
我之前遇到过这个问题,当时我没有像您一样为 download 方法添加第五个参数。不过,我没有检查错误消息,然后让它工作,毕竟删除了整个文件传输,所以无法验证。
反正这个参数叫trustAllHosts默认为假。因此,传递 true 作为第五个参数对我有用。请尝试一下,如果这不起作用,让我们找出更多。
另外,既然您在这个问题上提到了您问的最后一个问题,请accept如果它确实帮助您解决了您在标题中声称的问题,请在此回答。
关于cordova - Android 上的 PhoneGap Build : cordova. 文件传输下载总是失败,代码为 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27592437/