Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

280
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda