Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!