Multipart form data is not working in react native

Viewed 261

I'm trying to make an api call with multipart as content-type. when I added the params to FormData, it is creating multiple array lists.

 var formData = new FormData();

formData.append('name', "Mahendra")
formData.append('number', "12131233123")
formData.append('image', {uri : pathToImage, name : "image", "type":"image/jpeg"})
console.log(formData)

When I log the request, I'm getting multiple arrays inside. Below is the request

{"_parts" : [["name","Mahendra"],["number","12131233123"],["image",{"uri":"/Users/XXXXC/Library/Developer/CoreSimulator/Devices/XXXXX/data/Containers/Data/Application/XXX/tmp/react-native-image-crop-picker/asdas3D4.jpg","name":"image","type":"image/jpeg"}]]}

Can someone help me on this ?

Thanks in advance!

1 Answers

I'm not really sure to understand at which point you log them, but following the MDN docs, you shouldn't access the value directly but through the api methods. To send the data you have to use either XMLHttpRequest.send() or the fetch api

Related