Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

346
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda