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

107
Views
curl succeed but Javascript fetch failed

I have my JS fetch code this:

var myHeaders = new Headers();
myHeaders.append("accept", "application/json");
myHeaders.append("Authorization", "Bearer asdfasdfasdfasdfasdf");
myHeaders.append("Content-Type", "multipart/form-data");

var formdata = new FormData();
formdata.append("images", fileInput.files[0], "_265_.pdf");
formdata.append("cards", fileInput.files[0], "_180_.pdf");
formdata.append("organization", "org");

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: formdata,
  redirect: 'follow'
};

fetch("https://site/route?match_cut=0.64&Img_cut=0.45&card_cut=0.45&Img_card_cut=0.45&card_img_cut=0.45", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Everytime I make this request to my server which is Fastapi, the response I got were always {detail: 'There was an error parsing the body'} Though, I can successfully call to my server with below curl command:

curl -X 'POST' \
  'https://site/route?match_cut=0.64&Img_cut=0.45&card_cut=0.45&Img_card_cut=0.45&card_img_cut=0.45' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer asdfasdfasdfasdfasdf' \
  -H 'Content-Type: multipart/form-data' \
  -F 'images=@_265_.pdf;type=application/pdf' \
  -F 'reference=' \
  -F 'cards=@_180_.pdf;type=application/pdf' \
  -F 'organization=org'

Is there something missing in my fetch request ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The line myHeaders.append("Content-Type", "multipart/form-data"); caused my server failed to parse the request, removing it make everything back to normal.

about 4 years ago · Juan Pablo Isaza Report
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!