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

245
Vistas
Combining angular-file-upload and multer

I have big headache to combine angular file upload plugin with multer to make it fully SPA. I stucked on uploading multiple files through multer.

This is how my multer options looks like: (node route.js file)

var upload = multer({
    storage: storage,
    limits: {
        //fileSize: 819200
    }
}).array('myFile');

this is my POST: (node route.js file)

router.post('/add/file', function(req, res, next) {
    upload(req,res,function(err) {
        console.log(req.files);
        if(err) {
            console.log("Error uploading file.");
        }
    });
});

this is inside my angular controller:

var uploader = $scope.uploader = new FileUploader({
    url: 'http://localhost:3000/add/file',
    alias: 'myFile'
});

uploader.filters.push({
    name: 'imageFilter',
    fn: function(item /*{File|FileLikeObject}*/, options) {
        var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
        return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
    }
});

It adds only 1st file and stucks - I don't get any error it just stucks - whole page works and I can send files again, but again only 1st file will be uploaded. Console shows that req.files have only 1 file (that first one)

I couldn't find any tutorial or anything on the Internet with angular-file-upload plugin, that's why I ask you guys

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

0

Not sure if you figured this out yet or not, but with sending multiple files over, the 'uploadAll' function will not send the next file until it receives a response back from the server. So the route should look like this. I also saw somewhere in the documentation that the response needs to be json...haven't tested whether or not this is true though

router.post('/add/file', function(req, res, next) {
    upload(req,res,function(err) {
        console.log(req.files);
        if(err) {
            console.log("Error uploading file.");
        } else {
        res.status(200).json({response: 'some response...'})
       }
    });
});

over 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