@RequestMapping(value = IMAGES + "/{fileName}.{fileType}") public void getImage( @PathVariable String fileName, @PathVariable String fileType, @RequestParam(required = false) String version, HttpServletResponse response) throws IOException { FileImageFinder.FileInfo file = imageFinder.getFile(fileName + "." + fileType, version); response.setContentType(MediaType.parseMediaType("image/" + fileType).toString()); response.setContentLength(file.bytes.length); response.setHeader("Last-Modified", file.modifyTime); response.setHeader("Cache-Control", "public, max-age=3153600"); response.getOutputStream().write(file.bytes); }
@RequestMapping(value = IMAGES, method = POST) public String addImage( @RequestParam("image") MultipartFile file, DefaultMultipartHttpServletRequest request, Locale locale) throws IOException { // NOTE: Checking user rights and CSRF-Token needs to be done here because HttpUserService gains // NOTE org.eclipse.jetty.server.Request which is not able to handle parameters at // multipartrequests User currentUser = userService.getCurrentUser(false); if (!currentUser.isOm()) { throw new AccessDeniedException("Om rights required"); } userService.verifyCSRFToken(request); imageFinder.validateAndSaveFile(file); return redirectWithMessage( request.getHeader("Referer"), RequestMessage.EDITOR_UPLOAD_IMAGE, request); }
@RequestMapping(value = IMAGE_JSON, produces = JSON) public @ResponseBody List<FileImageFinder.FileJson> files() { return imageFinder.getImages(); }