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

152
Views
How to display the blob image stored in mysql using javascript?

I want to receive the blob image stored in the longblob type 'menuImg' column and put it in the img tag with the id 'img'. Help me!

['/admin/getMenuImg' Router source]

router.get('/getMenuImg', function (req, res) {
    //var menuNo = req.body.menuNo;
    var query = `SELECT menuImg FROM menu WHERE menuNo = 1`;

    connection.query(query, function (error, result) {
        if(error) {
            console.log("error ocurred: ", error);
            res.json({ "code": 400, "result": "error ocurred" })
        } else {
            console.log("get menuImg success");
            res.json({"code": 200, "result": "get menuImg success", "menuImg": result[0].menuImg})
        }
    })
})

[html source]

<body>
    <img id="img" width="400" height="400">
</body>
<script>
    $.ajax({
        url:'/admin/getMenuImg', // Maybe this is wrong
        cache:false,
        xhr:function(){
            var xhr = new XMLHttpRequest();
            xhr.responseType= 'blob'
            return xhr;
        },
        success: function(data){
            var img = document.getElementById('img');
            var url = window.URL || window.webkitURL;
            img.src = url.createObjectURL(data.menuImg);
        },
        error:function(){
            
        }
    });
</script>
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!