Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda