@RequestMapping( value = "/docreateprzepis", headers = "content-type=multipart/*", method = RequestMethod.POST) public String doCreatePrzepis( Model model, Przepis przepis, BindingResult result, Principal principal, RedirectAttributes redirectAttributes, @RequestParam(value = "photo", required = false) MultipartFile file) { przepis.setUser(usersService.findUser(principal.getName())); przepis.setData(new Date()); if (!(file.getSize() == 0)) { try { przepis.setPhoto(file.getBytes()); } catch (Exception re) { logger.info(re.getMessage()); return "createprzepis"; } } else { try { ClassPathResource cpr = new ClassPathResource("default.png"); InputStream is = cpr.getInputStream(); przepis.setPhoto(IOUtils.toByteArray(is)); // logger.info("czy photo jest rózne od null"); // logger.info(przepis.getPhoto() != null); } catch (IOException re) { logger.info(re.getMessage()); return "createprzepis"; } } przepisyService.createPrzepis(przepis); redirectAttributes.addAttribute("id", przepis.getId()); return "redirect:/przepis"; }