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

137
Vistas
How to store an html input image file to a file locally on the server

I want to store the image uploaded in a simple html input

<input
      type="file"
      name="thumbnail"
      id="image-input"
      accept="image/png, image/jpg, image/jpeg"
      hidden
 />

This leads to a post request when submitted

router.post('/dish/new',async (req,res) => {
  let { name, desc, cost, isnonveg, thumbnail} = req.body;
  fs.writeFile(path.join(__dirname,'../userdata/images/dishes','g.jpg'),thumbnail, ()=>{
    console.log('image stored')
  })
})

I want to store whatever the user uploads using node fs How can I go about doing this. The approach I use here merely stores the name of the file instead of the actual file.

almost 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

if you are using express you can add this attribute to form tag enctype="multipart/form-data". Then your image will be sent from frontend . To receive the image in the server you need to configure a middleware called express-fileupload

var fileupload = require("express-fileupload");

then you can register the middleware by app.use(fileupload()); in your app.js file

in your route file

    router.post('/something', async (req, res) => {
let image=req.files.fieldName

})


image.mv('./public/images/foldername/' + 'imageName' + '.jpg', (err) => {
  if (err) {

console.log(err)

  } else {

res.redirect('/)



}})

once it is done when you submit your form you can see the uploaded image in your server /public/images/foldername .

almost 4 years ago · Santiago Trujillo Denunciar
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