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

218
Vistas
multipart/form-data not being automatically set with axios in React Native

When attempting to upload a file to Amazon S3 using axios, I have been encountering a very strange issue. Normally, in a web browser, when FormData has binary data in it, the Content-Type header automatically gets set to multipart/form-data; boundary=<some random string>. However, I have been completely unable to achieve that in React Native (testing on an iOS device). The Content-Type is automatically set to application/json, and thus not being detected as a correctly formatted body when uploading to Amazon S3. I have tried specifying a blob in the file parameter in FormData instead of the URI to the file as well to no avail. I have appended my code below, any advice would be very much appreciated.

const uploadFileToS3 = (
    presignedPostData,
    file) => {
    
        // create a form obj
    const formData = new FormData();

    // append the fields in presignedPostData in formData
    Object.keys(presignedPostData.fields).forEach(
    key => {
        formData.append(
        key,
        presignedPostData.fields[key],
        );
    },
    );

    // append the file and uplaod
    const getBlob = async () => {
    const img_url = previewPath;
    let result = await fetch(img_url);
    const blob = await result.blob();
    formData.append('Content-Type', 'image/jpeg');
    formData.append('file', {
        uri: previewPath,
        type: 'image/jpeg',
        name: 'test.jpeg',
    });
    console.log(formData, 'wild');
    // post the data on the s3 url
    axios
        .post(presignedPostData.url, formData)
        .then(function (response) {
        console.log(response);
        })
        .catch(function (error) {
        console.log(error.response);
        });
    };
    getBlob();
};
about 4 years ago · Juan Pablo Isaza
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