Error: Multipart: Boundary not found axios request (React Native)

Viewed 1474

How do I set headers in axios post request ? I keep getting Multipart:Boundary not found (React Native)

I have tried setting the boundary as an arbitrary number like so but that still doesn't work. - 'Content-Type': 'multipart/form-data; boundary=--hadhba122--'

import axios from 'axios'


### upload image section ###
const uploadImage = async (uri: string) => {
  let fileType = uri.substring(uri.lastIndexOf('.') + 1)
  const baseUrl = 'localurl'
  const formData = new FormData()
  const imageJSON = {
    uri,
    type: `image/${fileType}`,
    name: `photo.${fileType}`,
  }

  formData.append('image', imageJSON)
  const config = {
    headers: {
      'Content-Type': 'multipart/form-data;',
    },
    data: formData,
  }
  return await axios
    .post(baseUrl, formData, config)
    .then((result) => {
      console.log('i am the result status', result.status)
      console.log(result)
    })
    .catch(console.error)
}





   
1 Answers

I have the same issue as you and have spent three days on it. Later today moved to fetch API.

Then it stroke me to downgrade the axios version and guess what, the Feature worked flawlessly i think it a bug in latest version of axios

My current version was 0.26 and i downgraded to 0.21

Related