這很讓人煩惱。前幾天,我無法使Cordova文件傳輸插件與PhoneGap 3.6.3配合使用。現在看來,在我重寫了index.js後,「undefinded」錯誤的問題已經得到解決。這是老問題:PhoneGap Build: Plugins not working (getting "undefined" errors) on AndroidPhoneGap生成:cordova.file-transfer下載總是失敗,在Android上的代碼爲3
現在我遇到了新的問題:在Android上下載總是失敗,出現以下消息:
FileTransferError
體:空
代碼:3
例外:null
http _status:401
源: 「http://www.hs-bremerhaven.de/fileadmin/images/logo.png」
目標: 「文件:///data/data/de.testapp1374839/files/logo.png」
原:對象
我已經嘗試過加入這些featue標籤到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
}
};
任何幫助將不勝感激。
401錯誤是未經授權的,所以,也許你的服務器不允許下載文件 – jcesarmobile
@jcesarmobile:我不認爲是這種情況,因爲你可以通過瀏覽器直接下載它。 –
曾經發現過這個問題的解決方案嗎?我有完全相同的問題。 –