javascript - Cordova FileTransfer 下载 - 总是返回错误 3

标签 javascript android cordova mobile phonegap-plugins

我在使用 cordova 插件文件传输时遇到了一些问题。这是我的代码:

window.requestFileSystem(
    LocalFileSystem.PERSISTENT,
    0,
    function onFileSystemSuccess(fileSystem) {
        fileSystem.root.getFile(
            "dummy.html", {create: true, exclusive: false},
            function gotFileEntry(fileEntry) {
                var sPath = fileEntry.fullPath.replace("dummy.html", "");
                var fileTransfer = new FileTransfer();
                fileEntry.remove();

                fileTransfer.download( 'http://cordova.apache.org/images/cordova_bot.png', sPath + photo.original_name,
                    function (theFile) {
                        alert('success: ' + JSON.stringify(theFile));
                        console.log("download complete: " + theFile.toURI());
                        // showLink(theFile.toURI());
                    },
                    function (error) {
                        alert('error: ' + JSON.stringify(error));
                        console.log("download error source " + error.source);
                        console.log("download error target " + error.target);
                        console.log("upload error code: " + error.code);
                    },
                    true
                );
            })
    },
    function (error) {
        alert('error request: ' + JSON.stringify(error));
    }
);

返回 fileTransfer.download 的错误回调,错误代码为 3,http 401。 我已经更新了 File 和 FileTransfer 插件,我的 cordova 版本是 4.3.0。 还检查了我的 config.xml 的

<access origin="*" />

但它就在那里。 我尝试添加标题 Connection: close,但没有结果。 也尝试将下载的第四个参数设置为其默认值(false) - 没有运气。

在 Android 平板电脑上进行测试。

有人有什么事吗?谢谢!

最佳答案

刚刚找到了我的问题的“解决方案”。 我所做的是将文件传输插件版本从 0.5.0 降级到 0.4.8。

如果有人遇到类似的问题,请执行以下操作:

  1. 通过运行“cordova plugins list”和“cordova plugin remove name_from_list”来删除现有文件传输插件
  2. 转到https://github.com/apache/cordova-plugin-file-transfer/releases并下载0.4.8版本的zip文件。
  3. 将文件解压到 cordova 应用程序的根目录中
  4. 运行“cordova 插件添加unzipped_folder 路径

就是这样。看起来效果不错,至少返回了成功回调,没有真正测试更多。

关于javascript - Cordova FileTransfer 下载 - 总是返回错误 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632141/

相关文章:

javascript - 为什么 Javascript 在 iPhone 上运行这么慢?

ios - 如何让应用程序在后台播放音频(iOS 上的 phonegap 1.5.0)

javascript - 等待 ajax 在函数中完成

javascript - 在 clearInterval() 之后恢复定时器

android - 在 Android WebView 中使用水平滚动

java - 如何在android中获取jsonarray值?

javascript - 蹦床功能操作原理

javascript - 如何在 React 中对状态(嵌套属性)进行小幅更新?

android - 如何仅返回主要联系人,就像在 Android People 应用程序中一样

android - cordova 添加平台 android 命令失败