在科尔多瓦3.1文件传输下载文件的问题 [英] File-transfer download file issue on Cordova 3.1

查看:316
本文介绍了在科尔多瓦3.1文件传输下载文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个使用科尔多瓦3.1我的第一个web应用。林在这个相当新的,所以请裸跟我来。

I'm currently creating my first webapplication using cordova 3.1. Im quite new at this so please bare with me.

在这个程序我需要能够将文件下载到手机上,然后打开它,但我不能似乎得到传递如何下载该文件。

In this app I need to be able to download a file to the phone and then open it, but i cant seem to get pass how to download the file.

林利用cordovas文档页面的文件传输code。 Everyting安装了CLI。
结果
这是多远我来:

Im using the file-transfer code from cordovas doc page. Everyting is installed with CLI.
This is how far i've come:


<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
   download();
}    

function download(){
        var filePath = '/mnt/sdcard';
        var fileTransfer = new FileTransfer();
        var uri = encodeURI("https://www.dropbox.com/s/27bxw65u4ga5is0/test.pdf");

        fileTransfer.download(
            uri,
            filePath,
            function(entry) {
                console.log("download complete: " + entry.fullPath);
            },
            function(error) {
                console.log("download error source " + error.source);
                console.log("download error target " + error.target);
                console.log("upload error code" + error.code);
            },
            false,
            {
                headers: {
                    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
                }
            }
        );
}

config.xml中

config.xml

<access origin="*" />
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>

和我的清单

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

该错误即时得到

 E/FileTransfer(878):     {"target":"\/sdcard\/test.pdf","source":"https:\/\/www.dropbox.com\/s\/27bxw65u4ga5is0\/tes t.pdf","http_status":0,"code":1}
 E/FileTransfer(878): java.io.FileNotFoundException:/sdcard/test.pdf: open failed: EACCES (Permission denied)
 E/FileTransfer(878):   at libcore.io.IoBridge.open(IoBridge.java:416)         E/FileTransfer(878):     at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
 E/FileTransfer(878):   at    org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:290)
 E/FileTransfer(878):   at org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:271)
 E/FileTransfer(878):   at org.apache.cordova.filetransfer.FileTransfer$4.run(FileTransfer.java:711)

我已经花了近2天了试图解决这个问题没有成功。因此,任何帮助都将是非常apperciated。

I've spent almost 2 days now trying to solve this issue without success. So any help at all would be very apperciated.

编辑:解决

删除科尔多瓦3.1手动安装2.7.0,并得到​​它的工作。

Removed Cordova 3.1 and installed 2.7.0 manually and got it to work.

推荐答案

不知道约3.1,但科尔多瓦的最新版本(3.3+),较新(1.0.0+)版本文件的文件系统使用的网址,而不是文件路径。事情是这样的:

Not sure about 3.1, but for the latest version of Cordova (3.3+), the newer (1.0.0+) version of File uses filesystem URLs instead of the file path. Something like this:

cdvfile://localhost/persistent/path/to/file

查看笔记在这个文档的底部:<一href=\"https://github.com/apache/cordova-plugin-file-transfer/blob/31ac00d3ae35f9ca280cf4e6c9edc9df23ea95b5/doc/index.md\">https://github.com/apache/cordova-plugin-file-transfer/blob/31ac00d3ae35f9ca280cf4e6c9edc9df23ea95b5/doc/index.md

See the notes at the bottom of this doc: https://github.com/apache/cordova-plugin-file-transfer/blob/31ac00d3ae35f9ca280cf4e6c9edc9df23ea95b5/doc/index.md

这篇关于在科尔多瓦3.1文件传输下载文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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