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

140
Views
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 answers
Answer question

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 Report
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!