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

219
Visualizações
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 à 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