I need to upload my datas from the frontend(react native mobile app) to the backend created using java spring boot. How i have done is by passing the params in the FormData like
let formData = new FormData();
let frontFile = { name:"file1",type:"image/png",uri:"<URI path of the image">}
let referenceNum = 12;
formData.append("file1", frontFile);
formData.append("referenceNum",referenceNum);
const config = {
headers: {
'Content-Type': 'multipart/form-data',
Accept: 'application/json',
},
};
axios
.post(
'MY API endpoint',
formData,
config,
)
.then((response) => console.log(response))
.catch((errors) => console.log(errors));
When try to do like this, it shows error like
Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile' for property 'backFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile' for property 'backFile': no matching editors or conversion strategy found
Note: The backend expects my data to always be multi-part type,but what the actual data sent to the server is [object object].It always shows type error. Any idea how to solve this issue?