Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

391
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda