I wanted to upload image and some more stuff with form from angular. This is VM object :
public class UserPictureVM {
private MultipartFile file;
private String type;
private String coverPosition;
And this is rest method :
@PostMapping("/user/upload-picture")
@Timed
public ResponseEntity<Void> uploadUserPicture(@RequestBody UserPictureVM userPicture){
This is Angular method that submit form :
saveCoverImage() {
const formData: FormData = new FormData();
formData.append('coverPosition', '0, 0');
formData.append('file', this.coverForm.file);
formData.append('type', 'cover');
this.profileService.uploadImages(formData)
.subscribe(res=> {
console.log(res);
})
}
But i get error :
Resolved exception caused by Handler execution: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;charset=UTF-8' not supported
You are submitting form with 3 request parameters. Because of that, you should change your controller method signature to this:
public ResponseEntity<Void> uploadUserPicture(
@RequestParam("coverPosition") String coverPosition,
@RequestParam("file") MultipartFile file,
@RequestParam("type") String type)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.