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

159
Vistas
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
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