Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. @PostMapping("/save")
  2. public String saveCourseWithPhoto(@ModelAttribute("course") Course course,
  3. @RequestParam("file") MultipartFile file) throws IOException {
  4. String fileName = StringUtils.cleanPath(file.getOriginalFilename());
  5.  
  6. if (!(fileName == null) || fileName.contains("..")) {
  7. InputStream photoInput = file.getInputStream();
  8. byte[] photoBytes = new byte[photoInput.read()];
  9. // InputStream inputStream = new ByteArrayInputStream(photoBytes);
  10. course.setPhoto(photoBytes);
  11. courseService.saveCourseWithPhoto(course);
  12. return "redirect:/profile";
  13. }
  14. .......
  15. return "redirect:/courses";
  16.  
  17. }
  18.  
  19. @Override
  20. public void saveCourseWithPhoto(Course theCourse){
  21. courseRepository.save(theCourse);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement