Download file Error 2, FileTransferError.INVALID_URL_ERR

I am using Phonegap [cordova 1.7.0] to download a file using Xcode [ios5]. This is the code I use 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 , and I don't know if I can solve it?

This is my journal:

  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 happened?

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

Thanks.

+6
source share
3 answers

If someone is facing the same problem, here is the answer:

To download a file, you should not just add the path to the folder where it will be downloaded, you should also add the path to the file itself.

So, if you upload a jpg-image in the "Documents", the path to the file 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'm not sure what I'm saying is 100% correct or not, but what worked for me, so hope this helps =)

+4
source

Sorry, I made a mistake, error code 2 should be INVALID_URL_ERR; So you can try a regular URL (not port 90, but 80 ports) for testing,

"http://184.172.195.202/ElmNoor/Documents/1.txt", persistent_root.fullPath + "/" + "1.txt", // attention, you must add

It should download normal.

0
source

What this error says is that you have a FileTransferError.INVALID_URL_ERR error. This means that the path you are trying to save the downloaded file is incorrect.

Cross your path by displaying it in console .

PS: You can verify the correct URL from which you are loading in a normal browser.

0
source

Source: https://habr.com/ru/post/915276/


All Articles