@PostMapping("/{userMobile}/uploadLogo")
public ResponseEntity<String> uploadBusinessLogo(
@PathVariable String userMobile,
@RequestParam("file") MultipartFile file // <-- Expects part named "file"
) {
//code
return uploadFile(file, userMobile, "logo");
}
trontend代码(REECT NATICE):
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;
};
使用
@RequestPart
不