2

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');
     res.send({'data':img});
     console.log(img);

Angular code is

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

1 Answer 1

1

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');
    console.log(base64Image);
    res.send(base64Image);

Angular js,

<img ng-src="data:image/jpg;base64,{{file_name}}" id="photo-id"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.