dimanche 8 mars 2015

How to read a nodejs stream in angular?

In nodejs I send a stream to clients like this:



DockerService.get().pull('my/image', function(err, stream) {
if (err) {
return res.badRequest(err);
} else {
return stream.pipe(res);
}
});


This is triggered from a angularjs client using $http.get:



pull: function() {
var url = ENV.apiEndpoint + '/docker/pull';
var promise = $http.get(url).success(function(response) {
return response;
}).error(function(data, status) {

});
return promise;
}


However I cannot read the stream. From angular I get an error message:



SyntaxError: Unexpected token {
at Object.parse (native)
at fromJson (file://build/vendor/angular/angular.js:1065:14)
at defaultHttpResponseTransform (file://build/vendor/angular/angular.js:8579:16)
at file://build/vendor/angular/angular.js:8664:12
at forEach (file://build/vendor/angular/angular.js:323:20)
at transformData (file://build/vendor/angular/angular.js:8663:3)
at transformResponse (file://build/vendor/angular/angular.js:9389:23)
at processQueue (file://build/vendor/angular/angular.js:13189:27)
at file://build/vendor/angular/angular.js:13205:27
at Scope.$get.Scope.$eval (file://build/vendor/angular/angular.js:14401:28)


I cannot find any information on how to handle streams in angular. Can you help me out?


Aucun commentaire:

Enregistrer un commentaire