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

404
Visualizações
JavaScript Express MySQL retrieves BLOB data as Buffer type. How to get as BLOB type?

I want to retrieve the BLOB from database as BLOB type but not Buffer type because the BLOB has a file type. The problem is I can update the BLOB file to database but when I retrieve the BLOB file, it represented as Buffer type instead. How can I get as BLOB file directly because I don't want to define type as only .JPG. I want to support the .PNG, .GIF .WEBP and vice versa.

phpMyAdmin database table for storing image files.

The query result is Buffer type, not Blob type from console.log()

<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff e2 02 28 49 43 43 5f 50 52 4f 46 49 4c 45 00 01 01 00 00 02 18 00 00 00 00 04 30 00 00 ... 1152932 more bytes>

Sending data to front-end then console.log() in the browser.

Here is my code for converting Buffer file to Base64 format then send it to the front-end for display as profile and profile setting for verifying an image upload.

 getAccountByUserID = (id,success) => {
    this.db.query(`SELECT u.UserID,u.Firstname,u.Lastname,u.Email,r.Role FROM user AS u JOIN role AS r ON u.UserID = r.UserID WHERE u.UserID = ?`,[id],(err,result)=>{
      if (err) throw err
      const account = result[0]

      this.db.query(`SELECT Image,Format,Data FROM profile WHERE UserID = ?`,[id],(err,result)=>{
        if (err) throw err
        const buffer = result[0]["Image"]
        const format = result[0]["Format"]
        const image = `data:image/jpg;base64,${buffer.toString("base64")}`
        const data = JSON.parse(result[0]["Data"])
        success({...account,["Image"]:image,["Data"]:data})
      })
    })
  }
about 4 years ago · Juan Pablo Isaza
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