Reputation: 1
I'm encountering a MissingServletRequestPartException when uploading files to my Spring Boot backend from a React Native/Expo app. The error states: Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required part 'file' is not present.]
Backend Code (Spring Boot):
@PostMapping("/{userMobile}/uploadLogo")
public ResponseEntity<String> uploadBusinessLogo(
@PathVariable String userMobile,
@RequestParam("file") MultipartFile file // <-- Expects part named "file"
) {
//code
return uploadFile(file, userMobile, "logo");
}
Frontend Code (React Native):
const uploadImage = async (uri: string, type: "Logo" | "Signature") => {
const formData = new FormData();
formData.append("file", {
uri,
name: `${type}_${Date.now()}.jpg`,
type: "image/jpeg",
} as any);
const endpoint = `http://localhost:8080/api2/business/${userMobile}/upload${type}`;
const response = await axios.post(endpoint, formData, {
headers: {
"Content-Type": "multipart/form-data", // Explicitly setting content-type
},
});
return response.data;
};
Upvotes: 0
Views: 38