Ejemplo n.º 1
0
  @RequestMapping(value = "hunter/addressbooks/upload", method = RequestMethod.POST)
  public Object upload(
      @RequestParam Long id,
      @RequestParam String companyName,
      @RequestParam(required = false) MultipartFile file) {
    Addressbook book = new Addressbook();
    book.setId(id);

    String fileName = file.getOriginalFilename();
    book.setAttachmentName(fileName);
    String pathname = path + companyName + "/";
    book.setAttachmentPath(pathname);
    try {
      File directory = new File(pathname + fileName);
      if (!directory.exists()) {
        directory.mkdirs();
      }
      file.transferTo(directory);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    addressbookService.update(book);
    return true;
  }