繁体   English   中英

Cordova文件传输插件下载总是产生http状态401和错误代码3

[英]Cordova file-transfer plugin download always yields http status 401 and error code 3

我正在使用Ionic为Android构建应用程序,当从设备进行测试时,我使用org.apache.cordova.file-transfer插件进行的调用总是产生相同的响应。

这是用于启动下载的代码:

  $scope.getFile = function(){ var filePath = cordova.file.dataDirectory + "beer.json"; var uri = encodeURI('https://stormy-sierra-8448.herokuapp.com/api/?q=stones+pale+ale'); var options = {}; $cordovaFileTransfer.download(uri, filePath, options, true) .then(function(result) { $scope.status = result; alert('success'); }, function(err) { console.log(err); }, function (progress) { $timeout(function () { $scope.downloadProgress = (progress.loaded / progress.total) * 100; }) }); } 

然后是响应(来自控制台)

 FileTransferError { code: 3, source: "https://stormy-sierra-8448.herokuapp.com/api/?q=stones+pale+ale", target: "documents/beer.txt", http_status: 401, body: null… } body: nullcode: 3exception: nullhttp_status: 401source: "https://stormy-sierra-8448.herokuapp.com/api/?q=stones+pale+ale" target: "documents/beer.txt" __proto__: FileTransferError 

我的环境如下:Cordova v5.0.0 Ionic 1.3.20

我已经看到其他人发布降级插件使其工作,但当我低于我正在使用的当前版本(0.5)时,该应用程序无法构建。 当我使用最新版本(1.0)时,应用程序会构建,但在启动后,控制台会说:

Uncaught module cordova-plugin-file.ProgressEvent not found - cordova.js:59

该设备具有连接并通过“设备”插件进行验证。

请帮忙!

最后,我将Angular引导到我的主index.html文件中的设备就绪事件。 一旦事件被触发,我不必担心插件没有被初始化并准备好使用,我认为这是FileTransfer插件让我失败的原因之一。

我做的另一件事是安装和使用$iconic命令的一切 之前,我正在混合$cordova [cmd]$ionic [cmd] 不确定它真的很重要,但现在一切似乎都正常。

自举逻辑如下。 我个人认为这是每个离子项目应该从一开始就设置的方式。 只需记住从身体标签或放置它的任何地方删除ng-app。

angular.element(document).ready(function() { if (window.cordova) { document.addEventListener('deviceready', function() { angular.bootstrap(document.body, ['myApp']); }, false); } else { angular.bootstrap(document.body, ['myApp']); } });

仍在使用最新版本的Cordova和Ionic。 :)

暂无
暂无

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

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