xcode 下载文件错误 2 , FileTransferError.INVALID_URL_ERR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10514533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:14:36  来源:igfitidea点击:

Download file Error 2 , FileTransferError.INVALID_URL_ERR

javascriptxcodecordovahttp-response-codes

提问by Sana Joseph

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:

我正在使用 Phonegap[cordova 1.7.0] 使用 Xcode[ios5] 下载文件。这是我用来下载文件的代码:

   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?

但是我收到错误代码 2& 我不知道我能解决它吗?

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 ?

我更改了 url,但它给出了相同的错误。你知道怎么回事吗?

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

PS:我知道这个问题并在下面添加了答案=)

Thanks.

谢谢。

采纳答案by Sana Joseph

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".

因此,如果您将 jpg 图像下载到“文档”,则文件路径应为:“文档”+“.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 =)

我不确定我说的是否 100% 正确,但这对我有用,,所以希望它有帮助 =)

回答by user1386827

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,

对不起,我弄错了,错误码2应该是INVALID_URL_ERR;所以,你可以试试普通的url(不是90端口而是80端口)进行测试,

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

"http://184.172.195.202/ElmNoor/Documents/1.txt",persistent_root.fullPath + "/" + "1.txt", //注意,一定要加

it should can download normal.

应该可以正常下载。

回答by Mahendra Liya

What this error says is - you have a FileTransferError.INVALID_URL_ERRerror. This means that the path at which you are trying to save your downloaded file is not correct.

这个错误说的是 - 你有一个FileTransferError.INVALID_URL_ERR错误。这意味着您尝试保存下载文件的路径不正确。

Cross-check your path by outputting it to the console.

通过将其输出到console.

PS: You can verify that the URL from which you are downloading is correct by trying it out in the normal browser.

PS:您可以通过在普通浏览器中尝试来验证您下载的网址是否正确。