Пример #1
0
  @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());
  }
Пример #2
0
  // 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();
  }
Пример #3
0
 @RequestMapping(URL.StorageFile.GALLERY)
 public String showGallery(Model model, Principal principal) {
   List<StorageFile> files = fileService.getAllForUser(principal.getName());
   model.addAttribute("files", files);
   return "file/gallery";
 }