Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

389
Views
How to show image in html using handlebars comes from MYSQL as blob

I want to show the store image as blob in HTML using handles bars

This is how I query the image in app.js

 app.get('/',(request,response)=>{
 db.query('select Image from pictures LIMIT 3', function(err, result) {
    
    let base64String = result.toString("base64");
    //var image = '<img src="'+base64String+'" class="denr-logo">';
   response.render('NPPNP',{images:base64String});
    //response.send(base64String);
    });    

Several sites they converted to base64 string and combined it with tag and 'data:image;base64,xxx=='

Actually I research several method, examples but I can't understand on how they do.

When I console.log the base64String, it showing [object Object] and when I pass it to the HTML nothing...

Using handlebars

  {{#each images}}
       {{this.Image}}
  {{/each}}

This is the result before converting to base64.

 [{"Image":{"type":"Buffer","data":[137,80,78,71,13,10,26,10,0,0,0,13............
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

First you'll need to get the binaries values using `result[0].Image' as we can see in your result

Second convert binaries to base64 this will give you like this iVBORw0KGgoAAAANSUhEU==

    var base = Buffer.from(result[0].Image);
    var conversion = base.toString('base64');
    var send = '<img src="data:image/png;base64,'+conversion+'" alt="something familiar"/>';
    response.send(send);

It might fixed your problem, I did it on my own and it worked

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!