javascript - how to display binary image in html using angularjs? -


i trying diplay binary data image in angularjs html form.i geeting 2 responses.i dono how avoid have enclosed screetshot.1st 1 response again passing bad response please 1 me out.i have enclose client , server side controller

client side controller  'use strict';    /**   * @ngdoc object   * @name test1.controllers.test1controller   * @description test1controller   * @requires ng.$scope  */  angular  .module('test1')      .controller('test1controller', [         '$scope','$http' ,'$location','$window',          function($scope,$http, $location,$window)  		{  	$scope.image = {};  var image="download.jpg";  			$http.get('*/upload/'+image).success(function(data,status,response)  {   		console.log(data);  		$scope.image=data;  	var testjpg = $scope.image;  document.getelementbyid("myimage").src = testjpg;  		});         }  ]);    backend controller    'use strict';        var mongoose = require('mongoose'),      _ = require('lodash');     var grid = require('gridfs-stream');  grid.mongo = mongoose.mongo;  var gfs = new grid(mongoose.connection.db);     exports.create = function(req, res) {                     console.log(req.files.filefield);              var part = req.files.filefield;                     var writestream = gfs.createwritestream({                      filename: part.name,                      mode: 'w',                      content_type:part.mimetype                  });                        writestream.on('close', function() {                       return res.status(200).send({                          message: 'success'                      });                  });                                    writestream.write(part.data);                     writestream.end();     };        exports.read = function(req, res) {         gfs.files.find({ filename: req.params.filename }).toarray(function (err, files) {             if(files.length===0){              return res.status(400).send({                  message: 'file not found'              });          }               res.writehead(200, {'content-type': files[0].contenttype});                    var readstream = gfs.createreadstream({                filename: files[0].filename          });                      var bufs=[];          readstream.on('data', function(data) {             // res.write(data);             bufs.push(data);          }).on('end', function() {             // res.end();             var fbuf = buffer.concat(bufs);             var base64 = (fbuf.tostring('base64'));              //console.log(base64 );             res.end('"data:image/jpeg;base64,' + base64 + '";');              });             readstream.on('error', function (err) {            console.log('an error occurred!', err);            throw err;          });      });     };
<div ng-controller="test1controller" >  <img ng-src="" id="myimage" />  </div>


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -