Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download file Error 2 , FileTransferError.INVALID_URL_ERR

I'm using Phonegap[cordova 1.7.0] to download a file using Xcode[ios5]. This is the code I'm using to download the file:

   function downloadfile(){
   var fileTransfer = new FileTransfer();
   console.log('the type of root is:');
   fileTransfer.download(
                  "http://184.172.195.202:90/ElmNoor/Documents/1.txt",
                  persistent_root.fullPath,
                  function(entry) {
                  alert("I'm Downloading");
                  console.log("download complete: " + entry.fullPath);
                  },
                  function(error) {
                  alert("I'm not downloading");
                  console.log("download error source " + error.source);
                  console.log("download error target " + error.target);
                  console.log("upload error code " + error.code);
                  }
                  );}

But I get Error code 2 & I don't know can I solve it?

This is my log:

     HelloPhoneGap[933:13403] File Transfer Finished with response code 200
     HelloPhoneGap[933:13403] [INFO] download error source http://184.172.195.202:90/ElmNoor/Documents/1.txt
     HelloPhoneGap[933:13403] [INFO] download error target /Users/weekend/Library/Application Support/iPhone Simulator/5.1/Applications/A7883F4B-7678-    4424-A93A-77747297A11E/Documents
     HelloPhoneGap[933:13403] [INFO] upload error code 2

I changed the url, but it gave the same error. Do you know what's wrong ?

PS: I knew the problem & added the answer below =)

Thanks.

like image 652
Sana Joseph Avatar asked May 09 '12 10:05

Sana Joseph


1 Answers

In case anyone is facing the same problem, here is the answer:

To download a file you shouldn't just add the path of the folder that it'll be downloaded in, you should also add the path of the file itself.

So if you are downloading a jpg image to "Documents", file path should be: "Document"+".jpg".

here is the code after modification:

   function DownloadFile(){
   var fileTransfer = new FileTransfer();
   var url ="http://www.ranafrog.org.au/f006.jpg";
   var folderpath=persistent_root.fullPath+"frog.jpg"; //The path is added here.
   var onSuccess= function(entry){
   console.log("download complete: " + entry.fullPath);
};

var onError=function(error) {
    console.log("download error source " + error.source);
    console.log("download error target " + error.target);
    console.log("upload error code " + error.code);
};

fileTransfer.download(url,folderpath,onSuccess,onError);
} 

I don't not sure whether what I'm saying is 100% correct or not, but that's what worked for me ,,, so hope it helps =)

like image 191
Sana Joseph Avatar answered Sep 30 '22 19:09

Sana Joseph