I add a row to databse with upload image . when i consult the list of rows , the image is appears, but when i try for update a row i encounter the error "Failed to load resource: the server responded with a status of 400 :spring mvc". image not appears!!
//add row
@RequestMapping(value = "/add")
public String ajouter(@ModelAttribute("serv") Service service ,MultipartFile file) throws Exception {
Long idser;
// add
if (service.getIdService() ==0) {
service.setImgService(file.getOriginalFilename());
idser = metier.addservice(service);
// add new image file
if (!file.isEmpty()) {
String path = System.getProperty("java.io.tmpdir") + "/"
+ idser + "_" + service.getImgService();
file.transferTo(new File(path));
}
}
return "redirect:/page/pageus";
}
// update
@RequestMapping("/edit/{id}")
public ModelAndView editService(@PathVariable("id") long id,Model model,@ModelAttribute Service service){
service=metier.getService(id);
model.addAttribute("editedserv",service);
return new ModelAndView("Admin/page/pageedit","serviceObject",service);
}
// get image of the products
@RequestMapping(value = "Photoser", produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public byte[] photoCat(Long idser) throws Exception {
Service serv = metier.getService(idser);
String path = System.getProperty("java.io.tmpdir") + "/" + idser+"_"+serv.getImgService();
File serImage = new File(path);
return IOUtils.toByteArray(new FileInputStream(serImage));
}
//show img in jsp
<img src="Photoser?idser=${serviceObject.idService}"/>
can someone help me !