PhoneGap Build: loading cordova.file-transfer always with code 3 on Android

This is annoying. A few days ago, I was unable to connect the Cordova file transfer plugin to work with PhoneGap 3.6.3. Now it seems that the problem with "undefinded" errors was resolved after I rewrote index.js. This is an old problem: PhoneGap Build: plugins not working (getting "undefined" errors) on Android

Now I am facing a new problem: The download on Android always failed with the following message:

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

I've already tried to add these featue tags to my config.xml file:

<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/network"/>

      

And I have provided a template for accessing external resources.

<access origin="*"/>

      

This is the updated 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
  }
};

      

Any help would be appreciated.

+3


source to share


1 answer


I had a problem with this before, where I didn't add the 5th parameter for the boot method like you did. I however didn't check the error messages and then got it working and after all deleted the entire transfer file so I can't check.

In any case, this parameter is called trustAllHosts , and by default it is false. So passing a true fifth parameter worked for me. Please try and make it clear if that doesn't work.



Also, since you are referencing the last question you asked on this issue, accept answer there if it helps you solve your problem as you are claiming the title.

0


source







All Articles