Cordova FileTransfer下载错误 [英] Cordova FileTransfer Download error

查看:179
本文介绍了Cordova FileTransfer下载错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的混合应用程序,应该使用cordova 2.3.0下载文件。从文档中:

I have a simple hybrid app which should download files with cordova 2.3.0. From the documentation:

var filePath = someFullPath; //e.g. "file:///mnt/sdcard/myfile.pdf"
var uri = encodeURI("http://someurl.com/myfile.pdf");

var fileTransfer = new FileTransfer();

fileTransfer.download(
            uri,
            filePath,
            function(entry) {
                console.error("download complete: " + entry.fullPath);
            },
            function(error) {
                console.error("download error source " + error.source);
                console.error("download error target " + error.target);
                console.error("donwload error code " + error.code);
                console.error("http: "+error.http_status);

            }
    );
}

结果是错误3,Connection_Err,与http_status 401,资源myfile。 pdf在没有必需的http服务器上公开。

The outcome is error 3, Connection_Err, with http_status 401, the resource myfile.pdf is public on a http server with no auth required.

我已尝试使用getFile(my)创建文件文件://mnt/sdcard/myfile.pdf file.pdf,{create:true,exclusive:false},success,fail);或者只是将字符串设置为现有目录。在这两种情况下都不行。

I have tried both creating the file file://mnt/sdcard/myfile.pdf with getFile("my file.pdf", {create: true, exclusive: false}, success, fail); or just setting a string to an existing directory. It didn't work in both scenarios.

你能告诉你吗?我必须使用cordova 2.3.0。

Can you please advise? I have to use cordova 2.3.0.

更新:

我认为我的问题非常接近于这一个: PhoneTransfer在Phonegap代码401

I think my problem is very close to this one: FileTransfer in Phonegap code 401

我有Android API 17,cordova 2.3.0,我需要设置allow origin =*,但是我无法创建config.xml文件,由于某些原因它抛出错误。你有遇到这个问题吗?

I have Android API 17, cordova 2.3.0, I need to set allow origin = "*", but I can't create the config.xml file, for some reasons it throws errors. Have you faced this problem?

我创建了文件夹xml里面的res(没有一个),并在这样的文件夹内创建一个文件config.xml。 config.xml的内容是

I created the folder xml inside res (there wasn't one) and created a file config.xml inside such folder. The content of the config.xml is

 <access origin="*"></access>

当我运行应用程序时,我收到一个警告与此错误:初始化Cordova:类未找到

when I run the application I get an alert with this error: Error Initializing Cordova: Class not found

推荐答案

所有的代码是正确的,这是我的框架配置的一个问题:

All the code was correct, it was a problem with my configuration of the framework:

这个项目有另一个项目作为图书馆依赖。该项目没有一个config.xml文件将网址列入白名单。图书馆项目已经!我只需要添加

this project had another project as library dependence. This project didn't have a config.xml file where to whitelist URLs. The library project had! I just needed to add the

<access origin="http://*.somedomain.com"></access> 

到rightconfig.xml cordova文件,它是在一个Library项目中,而不是在主要项目本身。

to the "right" config.xml cordova file, which was in a Library project, not in the main project itself.

这篇关于Cordova FileTransfer下载错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆