hi, i want to upload a user photo with user information. i work with angular6 and spring boot
my controller:
@PostMapping(value="/new",consumes=MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity createUser(@RequestPart("file") MultipartFile file, @RequestPart User user) throws IOException { if(file.isEmpty()) { return ResponseEntity.notFound().build(); } user.setPhoto(file.getBytes()); userRepository.save(user); return ResponseEntity.ok("user insert"); }
my service.ts
createUser(user: User,file : File) { const formData = new FormData(); formData.append('file', file); formData.append('user', JSON.stringify(user)); return this.http.post<User>(AppSettings.APP_URL + "/users/new", formData); }
hi, i want to upload a user photo with user information. i work with angular6 and spring boot my controller:
@PostMapping(value="/new",consumes=MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity createUser(@RequestPart("file") MultipartFile file, @RequestPart User user) throws IOException { if(file.isEmpty()) { return ResponseEntity.notFound().build(); } user.setPhoto(file.getBytes()); userRepository.save(user); return ResponseEntity.ok("user insert"); }
my service.tscreateUser(user: User,file : File) { const formData = new FormData(); formData.append('file', file); formData.append('user', JSON.stringify(user)); return this.http.post<User>(AppSettings.APP_URL + "/users/new", formData); }