Download file Error 2 , FileTransferError.INVALID_URL_ERR
-
06-06-2021 - |
문제
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.
해결책
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 =)
다른 팁
Sorry, i made a mistake, The error code 2 should be INVALID_URL_ERR; So, you can try a normal url(not 90 port but 80 port) for test,
"http://184.172.195.202/ElmNoor/Documents/1.txt", persistent_root.fullPath + "/" + "1.txt", //attention, must add
it should can download normal.
What this error says is - you have a FileTransferError.INVALID_URL_ERR
error. This means that the path at which you are trying to save your downloaded file is not correct.
Cross-check your path by outputting it to the console
.
PS: You can verify that the URL from which you are downloading is correct by trying it out in the normal browser.