/*
   @RequestMapping(value = "/uploadfile.html", method = RequestMethod.GET)
   public String uploadFile(){
   	return "uploadfile";
   }
  */
  @RequestMapping(value = "/uploadfile.html", method = RequestMethod.POST)
  public String processUploadPreview(
      @RequestParam("file") MultipartFile file,
      @RequestParam("id") Integer recordId,
      Map<String, Object> respMap) {
    Record record = recordService.getRecord(recordId);
    respMap.put("record", record);
    if (record == null) {
      // respMap.put("errMesg", "Incorect or not available record");
      return "redirect:records.html";
    }
    respMap.put("id", recordId);
    if (file.getSize() > 5242880) {
      respMap.put("errMesg", "Max file size 5MB");
      return "redirect:editrecord.html";
    }
    if (file.getName().equals("")) {
      respMap.put("errMesg", "File not selected");
      return "redirect:editrecord.html";
    }

    File newFile = new File();
    newFile.setRecord(record);
    newFile.setFilename(file.getOriginalFilename());
    newFile.setType(file.getName());
    try {
      newFile.setFile(file.getBytes());
      fileService.addFilele(newFile);
    } catch (Exception e) {
      respMap.put("errMesg", "Server error");
      e.printStackTrace();
      return "redirect:editrecord.html";
    }
    return "redirect:editrecord.html";
  }