title: How can i make multer 'upload.fields' optional?
body: <p>I have this 'post' method but it only works when i have both archives ('avatar' and 'document') uploaded, if i don't set them while sending the request, it ends with an error, how can I make the archives upload optional? I've already tried using 'upload.array', but it doesn't work as well.</p>
  <p>Here is the parts of the code mentioned.</p>
  <pre><code>const cpUpload = upload.fields([{ name: 'avatar', maxCount: 1 }, { name: 'document', maxCount: 1 }])
  app.post('/engajamentos',verifyJWT,cpUpload, async function(req, res){   
      var requisicao = req.body;
  
      var Categoria = requisicao.Categoria;
      var Tarefas = requisicao.Tarefas;
      var Estado = requisicao.Estado;
      var Municipio = requisicao.Municipio;
      var Criticidade = requisicao.Criticidade;
      var GT = requisicao.GT;
      var Restrito = requisicao.Restrito;
      var Foto = requisicao.Foto;
      var Doc = requisicao.Doc;
      var Tema = requisicao.Tema;
      var Descricao = requisicao.Descricao;
      var Contato = requisicao.Contato;
      var Stakeholder = requisicao.Stakeholder;
      var Participantes = requisicao.Participantes;
      var AreasEnvolvidas = requisicao.AreasEnvolvidas;
      var Data = requisicao.Data;
      var IncidentePotencial = requisicao.IncidentePotencial;
      var PossibilidadeDesdobramento = requisicao.PossibilidadeDesdobramento;
      var DemandaTratamento = requisicao.DemandaTratamento;
      var Inicio = requisicao.Inicio;
      var Previsao = requisicao.Previsao;
      var Prazo = requisicao.Prazo;
      var Conclusao = requisicao.Conclusao;
      var obs = requisicao.obs;
  
      let foto = '';
      let doc = '';
   
  
      //VERIFICAÇÃO DE REGISTRO FOTOGRAFICO
      if(req.files['avatar'].length == 0){
          foto='';
       }else{
          
           foto=caminhoFoto+req.files['avatar'][0].filename;
       }
       
      if(req.files['document'].length == 0){
          doc='';
       }else{
          
           doc=caminhoFoto+req.files['document'][0].filename;
       }
       
      
  
      let retorno = JSON.stringify(requisicao);
     // console.log(retorno.length);
  
      //console.log(Conclusao);
  
      //VERIFICA SE ESTÁ VAZIO
      if(retorno.length === 2){
          //console.log(&quot;está vazio!&quot;);
          res.send(&quot;está vazio!&quot;);
      }else{
        
          //FAZ CONEXÃO COM O BANCO 
          await connection.getConnection(async function(err, connectionx){
              if(err){
                  response.status(503).json({erro:'conexao'});
              }else{
                  
          //FAZ A INSERÇÃO DOS DADOS NO BANCO 
          await connectionx.query(&quot;INSERT INTO engajamentos(Categoria, Tarefas, Estado, Municipio, Criticidade, GT, Restrito, Foto, Doc, Tema,&quot; +
         &quot;Descricao, Contato, Stakeholder, Participantes, AreasEnvolvidas, Data, IncidentePotencial, PossibilidadeDesdobramento, DemandaTratamento, &quot; + 
         &quot;Inicio, Previsao, Prazo, Conclusao, obs)&quot; + &quot;VALUES&quot;+ &quot;(&quot; +
         &quot;'&quot;+ Categoria +&quot;'&quot;+&quot;,&quot;+
         &quot;'&quot;+ Tarefas +&quot;'&quot;+&quot;,&quot;+         
          &quot;'&quot;+ Estado +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Municipio +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Criticidade +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ GT +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Restrito +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ foto +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ doc +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Tema +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Descricao +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Contato +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Stakeholder +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Participantes +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ AreasEnvolvidas +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Data +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ IncidentePotencial +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ PossibilidadeDesdobramento +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ DemandaTratamento +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Inicio +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Previsao +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Prazo +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ Conclusao +&quot;'&quot;+&quot;,&quot;+
          &quot;'&quot;+ obs +&quot;'&quot;
          +&quot;)&quot;, function(err,results,fields){
              if(err){
                          response.status(503).json({erro:'query'});
                      }else{
                          res.send(results);
                          connectionx.release();
  
                      }
          })
      }
      })
  
      } 
  
  });```
  </code></pre>