MANJU MOHAN MANJU MOHAN - 2 years ago 179
AngularJS Question

How to stream a file from node js to angular js

I am new in angular and node js. I am trying to send file contents from node to angular. But i can't read it from my angular code

Here is my code

Node express

var img = fs.readFileSync('./test.jpg');
//res.writeHead(200, {'Content-Type': 'image/jpg' });
//res.end(img, 'binary');

Angular code is

<img ng-src="data:image/JPEG;base64,{{image}}">

Answer Source

Try this code,

    var img = fs.readFileSync('./test.jpg');

    fs.readFile('./test.jpg', function(err, original_data){

    var base64Image = new Buffer(original_data, 'binary').toString('base64');

Angular js,

<img ng-src="data:image/jpg;base64,{{file_name}}" id="photo-id"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download