Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

393
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda