上传图片415异常:"Content type 'multipart/form-data;' .... not supported"

问题

上传图片时报错:
Content type ‘multipart/form-data;boundary=----WebKitFormBoundarypOpfYxCGU6Q4sciA;charset=UTF-8’ not supported

上传图片415异常:
Controller层:

@PostMapping(path = "/uploadRotationImg")
public ResponseEntity<String> uploadRotationImg(@RequestParam("photos") MultipartFile file, @RequestBody ImgRotation imgRotation) {
	try {
		// 进行上传操作
		return imgRotationService.uploadRotationImg(file, imgRotation);
	} catch (Exception e) {
		// 上传失败
		e.printStackTrace();
		return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
	}
}

解决

去掉@RequestBody注解就行了

@PostMapping(path = "/uploadRotationImg")
public ResponseEntity<String> uploadRotationImg(@RequestParam("photos") MultipartFile file, ImgRotation imgRotation) {
	try {
		// 进行上传操作
		return imgRotationService.uploadRotationImg(file, imgRotation);
	} catch (Exception e) {
		// 上传失败
		e.printStackTrace();
		return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
	}
}

你可能感兴趣的:(踩坑经历)