I am new to react native. I want to upload images to server in react native. And I want to upload it in multipart format. so pleas help me. is it possible to upload images to server in multipart format is yes then How. I check and search lots of stuff on google But I did not find any single answer of uploading images to server in multipart. please help. thanks.
We can create a request using FormData class to upload images to a server in multipart.
for example:
const formData = new FormData();
formData.append('KEY1', VALUE1);
formData.append('KEY2', VALUE2);
formData.append('upload_pancard',
{
uri: pancardImage.uri,
name: 'pancardImage.jpg',
type: 'image/jpg'
}
);
formData.append('upload_aadhar',
{
uri: upload_aadhar.uri,
name: 'upload_aadhar.jpg',
type: 'image/jpg'
}
);
formData.append('upload_aadhar_second',
{
uri: upload_aadhar_second.uri,
name: 'upload_aadhar_second.jpg',
type: 'image/jpg'
}
);
formData.append('digital_signature',
{
uri: digital_signature.uri,
name: 'digital_signature.jpg',
type: 'image/jpg'
}
);
if you are supposed to upload multiple images then pass the array in the formData.append() to upload multiple images.