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

142
Vistas
Problem uploading image to local folder with node and Multer

I'm struggling uploading an image to a local folder using Node and Multer. The response i get it's successfully, but the image don't save in the folder. I have already lost a week trying to fix it

And yes, i have checked the destination route, in case you wonder.

This is my frontend:

<form id="tasasImage" enctype="multipart/form-data" style="display: flex; flex-direction: column;">
  <input type="file" name="photo" id="photo" class="file"> <br> 
  <div id="uploadImg" class="btn btn-primary">ENVIAR</div>
</form>

<script>
 $("#uploadImg").click(function () {
    if ($('#photo').val().length > 0) {
      var formData = new FormData($('#tasasImage')[0]);
      console.log([...formData])
      $.ajax({
          url: "",
          data: formData,
          type: "POST",
          processData: false,
          contentType: false,
          success: function(r){
            console.log('Uploaded successfully');
            $("#photo").val('');
          },
          error: function (e) {   
            console.log("some error", e);
          }
      });
  }
 </script> 

And the backend:

var storageTasas = multer.diskStorage({
    destination: function(req, file, callback) {
       callback(null, config.urlBase+'public/images/tasas');
  },
    filename: function(req, file, callback) {
       var name = now+'-'+file.originalname;
       callback(null, name);
  }
})

var uploadTasas = multer({ storage: storageTasas }).single('photo'); 

const tasasUploadImage = (req, res) => {
    uploadTasas(req, res, (err) => {
       if (err) { console.error(err); } 
       else {console.log('Ssuccessfully Uploaded') };
    })
    res.send({'file': now});
}

router.post('/admin/aliados/tasas/:id', adminController.tasasUploadImage);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. The url you are passing empty in the JQuery / Client script, it should be url : /admin/aliados/tasas/1234

  2. The form data should be like this var formData = new FormData($('#tasasImage'));

simple multipart file upload with express.js and multer with ajax

about 4 years ago · Juan Pablo Isaza 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