简体   繁体   English

Cordova FileTransfer下载错误

[英]Cordova FileTransfer Download error

I have a simple hybrid app which should download files with cordova 2.3.0. 我有一个简单的混合应用程序,应该使用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);

            }
    );
}

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. 结果是错误3,Connection_Err,带有http_status 401,资源myfile.pdf在http服务器上是公共的,不需要身份验证。

I have tried both creating the file file://mnt/sdcard/myfile.pdf with getFile("my file.pdf", {create: true, exclusive: false}, success, fail); 我已经尝试用getFile(“ my file.pdf”,{create:true,Exclusive:false},成功,失败)创建文件file://mnt/sdcard/myfile.pdf。 or just setting a string to an existing directory. 或只是将字符串设置到现有目录。 It didn't work in both scenarios. 在两种情况下都无法正常工作。

Can you please advise? 你能给些建议么? I have to use cordova 2.3.0. 我必须使用cordova 2.3.0。

UPDATE: 更新:

I think my problem is very close to this one: FileTransfer in Phonegap code 401 我认为我的问题非常接近这一问题: Phonegap代码401中的FileTransfer

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. 我有Android API 17,cordova 2.3.0,我需要设置allow origin =“ *”,但由于某些原因,它会引发错误,因此我无法创建config.xml文件。 Have you faced this problem? 你遇到这个问题了吗?

I created the folder xml inside res (there wasn't one) and created a file config.xml inside such folder. 我在res(没有一个)中创建了xml文件夹,并在该文件夹中创建了config.xml文件。 The content of the config.xml is config.xml的内容是

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

when I run the application I get an alert with this error: Error Initializing Cordova: Class not found 当我运行应用程序时,出现以下错误提示:初始化Cordova错误:找不到类

All the code was correct, it was a problem with my configuration of the framework: 所有代码都是正确的,这是我配置框架时遇到的问题:

this project had another project as library dependence. 这个项目还有另一个依赖库的项目。 This project didn't have a config.xml file where to whitelist URLs. 该项目没有将URL列入白名单的config.xml文件。 The library project had! 图书馆的项目了! I just needed to add the 我只需要添加

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

to the "right" config.xml cordova file, which was in a Library project, not in the main project itself. 到“正确”的config.xml cordova文件,该文件在Library项目中,而不在主项目本身中。

In my setup, having access was not sufficient. 在我的设置中,访问权限还不够。 I added plugin cordova-plugin-whitelist to my app. 我将插件cordova-plugin-whitelist添加到了我的应用中。 Then it worked fine. 然后工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM