admin管理员组文章数量:1356741
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 plete: " + 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.
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 plete: " + 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.
Share Improve this question edited May 9, 2012 at 13:49 Sana Joseph asked May 9, 2012 at 10:47 Sana JosephSana Joseph 1,9487 gold badges37 silver badges58 bronze badges3 Answers
Reset to default 4In 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.au/f006.jpg";
var folderpath=persistent_root.fullPath+"frog.jpg"; //The path is added here.
var onSuccess= function(entry){
console.log("download plete: " + 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.
本文标签: javascriptDownload file Error 2FileTransferErrorINVALIDURLERRStack Overflow
版权声明:本文标题:javascript - Download file Error 2 , FileTransferError.INVALID_URL_ERR - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744056867a2583414.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论