Пример #1
0
  @RequestMapping(value = "/submitpaper", method = RequestMethod.POST)
  public String submitPaper(MultipartHttpServletRequest request) throws Exception {
    String college = request.getParameter("college");
    String branch = request.getParameter("branch");
    String subject = request.getParameter("subject");
    String description = request.getParameter("description");
    List<MultipartFile> papers = request.getFiles("papers");

    PaperSubmitRequest paperSubmitRequest =
        new PaperSubmitRequest(college, branch, subject, description);
    paperSubmitRequestDao.save(paperSubmitRequest);

    serverStorage.uploadFiles(
        serverStorage.getRequestsDir() + paperSubmitRequest.getRequestID(), papers);
    return "redirect:/";
  }
Пример #2
0
  @ResponseBody
  @RequestMapping(value = "/increasecounter/{paperID}", method = RequestMethod.POST)
  public void increaseCounterAndDownloadPaper(
      @PathVariable("paperID") String paperID, HttpServletResponse response) {
    LOG.debug("Inside UserController.increaseCounter(), paperID = " + paperID);
    Paper paper = paperDao.get(Integer.parseInt(paperID));
    paper.increaseCounter();
    paperDao.save(paper);

    // Downloading Paper
    response.setHeader("Content-Disposition", "attachment; filename=" + paper.getPath());
    try {
      OutputStream out = response.getOutputStream();
      File file =
          serverStorage.getFirstFileFromDirectory(serverStorage.getPapersDir() + paper.getPath());
      out.write(FileUtils.readFileToByteArray(file));
      out.flush();
      out.close();
    } catch (IOException e) {
      LOG.error("Error while downloading Paper.", e);
    }
  }