2

I'm struggled with react native file upload using Axios form data. I set the content type as multipart/form-data. below is my request parts.

  • form-data body content

{"_parts":[["profileImage",{"name":"rn_image_picker_lib_temp_51ee6068-2b4b-4baf-a6c3-44b14b0b5b9b.jpg","type":"image/jpeg","uri":"file:///data/user/0/com.sentura.xchange/cache/rn_image_picker_lib_temp_51ee6068-2b4b-4baf-a6c3-44b14b0b5b9b.jpg"}],["email","xx@gmail.com"],["firstName","vv"],["lastName","ss"],["address","sdf"],["postalCode","2323"],["mobileNumber","0796677653"],["country","Anguilla"],["countryCode","+1264"]]}"

  • request headers
"headers":{
     "Accept":"application/json",
     "Authorization":"Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ2aWR1OTk2QGdtYWlsLmNvbSIsImV4cCI6MTY0NTk1ODYzNywiaWF0IjoxNjQ1OTU3NzM3fQ.GZMQFYGU4veH4xZ9ki2afWmtbGCKhOK5JruWLRX75nisVXXX9JmQYf31ns_ALVr9N1-RgcpMabolgHQSMZ7KIw",
     "Content-Type":"multipart/form-data"
  }

but from the spring boot side, it gives the below error. but this work in postman.

org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

Hope your support to resolve this. thanks!

2 Answers2

0

This works for me:

"Content-Type" : 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
0

Actually the issue happened with my react native version. i don't know what is the correct way to achieve it with newest react native versions. i worked with react native 0.67. unfortunately, it's broken.

I added the same code base to react native 0.64 and it worked well as i expected. didn't do any code change to axios or any other.