Я пытаюсь загрузить форму с файлом и данными формы, используя angular4 и весеннюю загрузку. я установил тип контента как multipart/form-data
, но он все равно показывает ошибку 400.
Моя угловая сторона
this.formobj["userID"] = this.userId;
this.formobj["userName"] = this.addfrm.value.userName;
this.formobj["userDescription"] = this.addfrm.value.userDes;
this.formobj["files"] = this.addfrm.value.image;
let type = new HttpHeaders();
type.append('Content-Type', 'multipart/form-data');
this.http.post(this.Core_URL + '/updateUserWithFile', this.formobj, {headers: type})
.subscribe(data => {
console.log("** form submited");
console.log(data);
this.clearShareObj();
this.r.navigateByUrl('home');
});
}
Серверная часть
На стороне сервера я использую пружинную загрузку
@PostMapping("/updateUserWithFile")
private FunctionInfo updateUserWithFile(@RequestBody UserInfo userInfo) {
System.out.println("ok");
int userId = userInfo.getUserId();
String userName = userInfo.getUserName();
MultipartFile[] files; = userInfo.getFile();
}
DomainClass
public class UserInfo {
private Integer userID;
private String userName;
private String userDescription;
private MultipartFile[] files;
}
После отправки его показывает мне следующие заголовки. тип содержимого не задан.
![enter image description here](https://i.stack.imgur.com/EKjp7.png)