错误:多部分:未找到 axios 请求边界(React Native)

tes*_*gdj 1 node.js react-native axios

如何在 axios post 请求中设置标头?我不断收到 Multipart:Boundary not found (React Native)

我尝试将边界设置为任意数字,但仍然不起作用。- '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)
}





   
Run Code Online (Sandbox Code Playgroud)

小智 6

我和你有同样的问题,已经解决了三天了。今天晚些时候转向获取 API。

然后它让我降级 axios 版本,你猜怎么着,该功能运行完美,我认为这是最新版本 axios 中的一个错误

我当前的版本是 0.26,我降级到 0.21