javascript - Cordova file-transfer plugin download always yields http status 401 and error code 3 -
i'm using ionic build app android, , when testing device, call make using org.apache.cordova.file-transfer plugin yields same response.
here's code used fire off download:
$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; }) }); } and response (from console)
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 my environment looks this: cordova v5.0.0 ionic 1.3.20
i've seen others post downgrading plugin made work, when go below current version i'm using (0.5), app doesn't build. when use newest version (1.0), app builds, after launches, console says:
uncaught module cordova-plugin-file.progressevent not found - cordova.js:59
the device has connection , verified 'device' plugin.
please help!
in end, bootstrapped angular device ready event in main index.html file. once event fired, didn't have worry plugins not being initialized , ready use, think 1 of reasons filetransfer plugin failing me.
another thing did install , use $iconic command everything. before, mixing $cordova [cmd] , $ionic [cmd]. not sure matters, seems working now.
the bootstrapping logic below. think how every ionic project should set get-go. remember remove ng-app body tag or wherever you've placed it.
angular.element(document).ready(function() { if (window.cordova) { document.addeventlistener('deviceready', function() { angular.bootstrap(document.body, ['myapp']); }, false); } else { angular.bootstrap(document.body, ['myapp']); } });
still using latest versions of cordova , ionic. :)
Comments
Post a Comment