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

343
Views
JS FormData sends file as application/ocet-stream, how to set it as multipart/form-data?

As in the title, I'm trying to upload file to Spring Rest Controller using:

handleOnChange() {
    let inputFile = document.getElementById("file-input");
    this.file.file = inputFile.files[0];
    this.file.filename = inputFile.value;
}

render() {
    return (
        <div className="file-input">
                <input id="file-input" type="file"
                    onChange={(event) => this.handleOnChange()} />
        </div>
    );
}

upload() {
let formData = new FormData();
formData.append("file", this.data.file.file, "/D:/temp/test2.xlf");
formData.append("request", JSON.stringify(request));

let reqOptions = {
    method: 'POST',
    body: formData
}

fetch('http://127.0.0.1:8081/multi-mt-evaluation/report', reqOptions)
    .then(response => response.json())
    .then(data => console.log(data));
}

But when fetch is called the file is sent as application/octet-stream, is there a simple, or more complicated way to set it as multipart/form-data?

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

0

Try specifying the content type by adding it to your request headers:

let reqOptions = {
    method: 'POST',
    body: formData,
    headers: {
          'Content-Type': 'multipart/form-data',
    },
}    
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!