【问题标题】:Meteor Cordova FileTransfer.download error CONNECTION_ERRMeteor Cordova FileTransfer.download 错误 CONNECTION_ERR
【发布时间】:2015-03-05 04:40:39
【问题描述】:

我正在尝试从外部服务器下载文件并将其本地保存到安卓的设备存储中。我正在使用:

var downloadFile = function () {

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
        var dir = fs.root.getDirectory("appImages", {create: true, exclusive: false}, function (dirEntry) {
            var file = dirEntry.getFile("image.png", {create: true, exclusive: false}, function (fileEntry) {
                var filePath = fileEntry.toURL();
                var fileTransfer = new FileTransfer();
                console.log('starting file download: ' + "https://www.google.com/images/srpr/logo11w.png" + ' to ' + filePath);
            fileTransfer.download(
                "https://www.google.com/images/srpr/logo11w.png",
                filePath,
                function () {
                    console.log('save');
                },
                function (error) {
                    console.log('failed to save image: ' + filePath + ' (error: ' + error.http_status + ')');
                    console.log(JSON.stringify(error));
                },
                true
            );
            });
        }, function (error) {
            console.log(JSON.stringify(error));
        });
    }, function (error) {
        console.log(JSON.stringify(error));
    });

};

我得到错误:

I20150303-14:44:20.104(-7) (android:http://meteor.local/test.js:55) starting file download: https://www.google.com/images/srpr/logo11w.png to file:///storage/emulated/0/appImages/image.png
I20150303-14:44:20.104(-7) (android:http://meteor.local/test.js:69) failed to save image: file:///storage/emulated/0/appImages/image.png (error: 401)
I20150303-14:44:20.104(-7) (android:http://meteor.local/test.js:70) {"code":3,"source":"https://www.google.com/images/srpr/logo11w.png","target":"file:///storage/emulated/0/appImages/image.png","http_status":401,"body":null,"exception":null}

文件路径已创建,我可以浏览到/appImages 并看到有一个损坏的image.png。在我的AndroidManifest.xml 我也有:

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

我的设备也已连接到互联网。感谢您的帮助!

【问题讨论】:

    标签: cordova meteor


    【解决方案1】:

    这个问题让我发疯了,但我终于想通了。我使用的文件传输版本不能很好地与流星配合使用。不起作用的版本是 0.5.0 而我使用版本 0.4.3 现在一切正常,

    已删除:meteor remove cordova:org.apache.cordova.file-transfer@0.5.0

    已添加:meteor add cordova:org.apache.cordova.file-transfer@0.4.3

    现在一切正常。

    【讨论】:

      【解决方案2】:

      这个问题的原因很少。

      1- 没有互联网连接或连接到 wifi。

      2- AndroidManifest.xml 中没有互联网权限

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

      【讨论】:

      • 感谢您的帮助,但两者都在场。
      猜你喜欢
      • 1970-01-01
      • 2015-08-03
      • 2018-02-03
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      • 2015-01-19
      • 1970-01-01
      • 2016-02-19
      相关资源
      最近更新 更多