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

156
Vistas
How to view image in img tag

I got problem that i cant get this code to save to image in a img tag. the picture will only show the first time i enter the site, the next time i enter the site it is gone. guess its the pipe but is there a way to keep it there? have searched for days now...

this is my code to save it and get it.

router.post('/', function(req, res, next) {
    var busboy = new Busboy({ headers : req.headers });
    var fileId = new mongo.ObjectId();
    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
        console.log('got file', filename, mimetype, encoding);
        var writeStream = gfs.createWriteStream({
            _id: fileId,
            filename: filename,
            mode: 'w',
            content_type: mimetype,
        });
        file.pipe(writeStream);
    }).on('finish', function() {
        // show a link to the uploaded file
        res.writeHead(200, {'content-type': 'text/html'});
        res.end('<a href="/showfile/' + fileId.toString() + '">blogginnlegg1</a>');
    });
    req.pipe(busboy);
});

//get file?
router.get('/file/:id', function(req, res, next){
    gfs.findOne({ _id: req.params.id }, function (err, file) {
        if (err) return res.status(400).send(err);
        if (!file) return res.status(404).send('');
        res.set('Content-Type', file.contentType);
        res.set('Content-Disposition', 'attachment; filename="' + file.filename + '"');
        var readstream = gfs.createReadStream({
            _id: file._id
        });
        readstream.on("error", function(err) {
            console.log("Got error while processing stream " + err.message);
            res.end();
        });
        readstream.pipe(res);
    });
});    
over 4 years ago · Santiago Trujillo
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