spring boot sissingservletrequestpartexception for'file',尽管@requestparam在multipart upload中正确@requestparam 我从React Native/Expo应用程序上将文件上传到我的Spring Boot Backend时会遇到MissingServletRequestPartexception。错误指出: 解决[org.springframework.web.multipart.supp ...

问题描述 投票:0回答:1
@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
spring spring-boot react-native
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.