Uploading two files from two different fields with multer

2

Using the multer I am trying to upload two different files that come from fields in forms different and has different storage path as well:

let storageAudios = multer.diskStorage({
  destination: (req, file, callback) => {
    callback(null, './uploads/audiographs');
  },
  filename: (req, file, callback) => {
    callback(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
  }
});

let uploadAudios = multer({
  storage: storageAudios
}).single('audiographs');



let storageEstablishments = multer.diskStorage({
  destination: (req, file, callback) => {
    callback(null, './uploads/establishments-logo');
  },
  filename: (req, file, callback) => {
    callback(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
  }
});

let uploadEstablishments = multer({
  storage: storageEstablishments
}).single('logo');

No controller of each route to upload I have:

addEstablishment: (req, res) => {
    uploadEstablishments(req, res, function(err) {
      if(err) {
        console.log(err)
        return res.end("error");
      }else{

        // ...

        console.log(req.file) // retornando undefined

        // ...
      }
    })
},
addAudio: (req, res) => {
  uploadAudios(req, res, function(err) {
    if(err) {
      console.log(err)
      return res.end("error");
    }else{

        // ...

        console.log(req.file) // retornando o arquivo esperado

        // ...
    }
  });
}

As you can see, the upload of the audios works, but that of the establishments does not. Am I doing something wrong?

Thanks in advance for any help.

    
asked by anonymous 29.03.2017 / 16:04

0 answers