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

400
Views
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
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!