@RequestMapping(URL.StorageFile.SHOW) public void show( @PathVariable(URL.StorageFile.P_STORAGE_FILE_ID) String fileId, HttpServletResponse response) throws IOException { StorageFile file = fileService.get(fileId); response.setContentType(file.getContentType().getContentTypeAsString()); response.setHeader("Content-disposition", "attachment; filename=" + file.getName()); response.getOutputStream().write(file.getData()); }
// TODO Validierung, ob es ein Bild oder eine andere Datei, am besten je // nach kontext anpassbar. @RequestMapping(value = URL.StorageFile.UPLOAD, method = RequestMethod.POST) public @ResponseBody String save( @Valid UploadFile uploadFile, BindingResult result, Principal principal) throws IOException { if (result.hasErrors()) { return result.getAllErrors().toString(); } log.debug("file Upload " + uploadFile.getName()); log.debug(uploadFile.getContentType() + " filename: " + uploadFile.getOriginalFilename()); String username = principal.getName(); StorageFile storedFile = uploadFile.toStorageFile(); storedFile.setUsername(username); fileService.save(storedFile); return storedFile.getId(); }