2014-12-21 20 views
3

這很讓人煩惱。前幾天,我無法使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 
    } 
}; 

任何幫助將不勝感激。

+0

401錯誤是未經授權的,所以,也許你的服務器不允許下載文件 – jcesarmobile

+0

@jcesarmobile:我不認爲是這種情況,因爲你可以通過瀏覽器直接下載它。 –

+0

曾經發現過這個問題的解決方案嗎?我有完全相同的問題。 –

回答

0

我之前遇到過這個問題,當時我沒有爲下載方法加上第五個參數就像你一樣。然而,我沒有,檢查錯誤信息,然後得到它的工作,並在全部刪除整個文件傳輸,所以無法驗證。

無論如何,這個參數被稱爲trustAllHosts,它默認爲false。所以通過true作爲第五個參數爲我工作。請嘗試一下,讓我們弄清楚,如果這不起作用。

另外,由於您在這個問題上提及您詢問的最後一個問題,請accept答案,如果確實有助於您在標題中聲明時解決問題。

相關問題