San*_*eph 6 javascript xcode http-response-codes cordova
我正在使用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);
}
);}
Run Code Online (Sandbox Code Playgroud)
但我得到错误代码2我不知道我可以解决它吗?
这是我的日志:
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
Run Code Online (Sandbox Code Playgroud)
我更改了网址,但它也犯了同样的错误.你知道什么是错的吗?
PS:我知道问题并在下面添加了答案=)
谢谢.
如果有人遇到同样的问题,答案如下:
要下载文件,您不应该只添加要下载的文件夹的路径,还应该添加文件本身的路径。
因此,如果您要下载 jpg 图像到“文档”,文件路径应为:“文档”+“.jpg”。
这是修改后的代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
我不确定我说的是否100%正确,但这对我有用,,,所以希望它有帮助 =)
| 归档时间: |
|
| 查看次数: |
6841 次 |
| 最近记录: |