title: Sending DataForm containing a pdf file from a node.js file
body: <p>I am trying to send a FormData containing a pdf file from a node.js script to a server. The request fail with a status code 400 in response.  In the server side, it seems that he do not consider the data as a pdf file, or maybe that that the whole data is undefined.</p>
  
  <p>This is what my node.js script does : (I've tried other ways to send the request but without success)</p>
  
  <pre><code>import axios from "axios"
  import fs from "fs-extra"
  import FormData from 'form-data'
  
  const formData = new FormData()
  const diplomaBuffer = await fs.readFile(`../data/fake/foo`+i+`.pdf`)
  
  formData.append("diploma", diplomaBuffer)
  formData.append("diplomaId", 1)
  
  axios({
    method: 'post',
    processData: false,
    contentType: 'multipart/form-data',
    cache: false,
    url: 'http://localhost:8080/certificates',
    data: formData,
    config: { headers: formData.getHeaders() }
  })
  
  // const response = await axios
  // .post(`http://localhost:8080/certificates`, {
  //     body: formData
  // })
  
  // const response = await axios
  // .post(`http://localhost:8080/certificates`
  //      , formData
  //      , {headers: formData.getHeaders()})
  </code></pre>
  
  <p>This is the function called in the server side :</p>
  
  <pre><code>app.post('/certificates', async (req, res) =&gt; {
          const files = req.files
  
          if(!files || !files.diploma || !files.diplomaId) {
              res.status(400).send(new Error("No file provided"))
          }
  
          if(files.diploma.mimetype !== "application/pdf") {
              res.status(400).send(new Error("diploma is not a pdf"))
          }
  
          // operations made with the received pdf (not relevant for the question)
          const certificateId = uniqid()
          const outputDiploma = `data/diplomas/${certificateId}.pdf`
  
          await Promise.all([
              fs.writeFile(outputDiploma, files.diploma.data),
          ])
  
          await pdf.sign(outputDiploma, `${sha("sha256").update(certificateId + diplomaSecret).digest("hex")} : ${date()}`)
  
          const diplomaBuffer = await fs.readFile(outputDiploma)
          const certificate_hash = verify_pdf.hashBuffer(diplomaBuffer)
  
          const certificateRegistry = await app.bizNetworkConnection.getAssetRegistry("consortium.supchain.assets.Certificate")
          const certificate = app.factory.newResource("consortium.supchain.assets", "Certificate", certificateId)
          certificate.diploma = app.factory.newRelationship("consortium.supchain.assets", "Diploma", req.body.diplomaId)
          certificate.hashInfo = certificate_hash
          await app.registry.certificate.add(certificate)
  
          res.status(200).send("ok")
      })
  </code></pre>