Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @PostMapping("/save")
- public String saveCourseWithPhoto(@ModelAttribute("course") Course course,
- @RequestParam("file") MultipartFile file) throws IOException {
- String fileName = StringUtils.cleanPath(file.getOriginalFilename());
- if (!(fileName == null) || fileName.contains("..")) {
- InputStream photoInput = file.getInputStream();
- byte[] photoBytes = new byte[photoInput.read()];
- // InputStream inputStream = new ByteArrayInputStream(photoBytes);
- course.setPhoto(photoBytes);
- courseService.saveCourseWithPhoto(course);
- return "redirect:/profile";
- }
- .......
- return "redirect:/courses";
- }
- @Override
- public void saveCourseWithPhoto(Course theCourse){
- courseRepository.save(theCourse);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement