Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
javascript pass multipart/form-data with pdf file

I am trying to pass a multipart/form-data for cucumber testing of a rest post api. I need to pass a pdf file. I am referring to https://www.npmjs.com/package/form-data. Here is my code:

let form = new FormData()    
form.append('content', process.stdout, {
        filename: 'test.pdf', // ... or:
        filepath: pdffilepath,
        contentType: 'application/pdf',
        knownLength: fs.statSync(pdffilepath).size
    });
await axios.post(url, form, {
  headers: {
    ...form.getHeaders(),
    'Content-Length': form.getLengthSync(),
    'content-type': multipart/for-data boundary=' + form.getBoundary()
}
});

If I pass process.stdout as one parameter in append function, it timed-out. I don't have any stdout object. I tried different form.append call by using fs.createReadStream, but it sends file octate stream. I want to send file type as pdf. Any help on this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!