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

266
Visualizações
Reactjs | How to make boundary static when content type is multipart/form-data

We are facing one issue while we are making file upload post call using React-JS, in dev-tools under form data we are getting some browser generated boundary.

------WebKitFormBoundarypSTl3xdAHAJgTN8A

enter image description here

And because of this random boundary we are getting issue while we are making call to a third party api.

Is there any way to make this boundary some fixed value. Something like this :

----somefixedvalue.

Here is the js code:

function doupload() {
let data = document.getElementById("file").files[0];
console.log('doupload',data);
let formData = new FormData();
formData.append("file", data);
fetch('http://localhost:8081/upload/multipart',
{
method:'POST',
body: formData,
headers: {
   'Content-Type': 'multipart/form-data; boundary=----somefixedboundary'
  }
}).then(res => {
       for(const header of res.headers){
           console.log(`resHeaderName: ${header[0]}, Value:${header[1]}`);
         }
     });
alert('your file has been uploaded');
location.reload();

};

can someone help me to solve this? I'm quite confused here as i have given content type along with some static boundary but no luck.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can convert a file to the binary string and prepare the body by yourself instead of using FormData as it shown in this answer.

But keep in mind that if this ----somefixedvalue substring appears in the file it will be considered a boundary causing body parsing error on receiver side. In case of FormData, browser should take care of it and prevent this.

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