Пример #1
0
 /**
  * Upload files.
  *
  * @param user current user
  * @param path path
  * @param description description
  * @param file multipart file
  * @param model model
  * @return script/scriptList
  */
 @RequestMapping(value = "/upload/**", method = RequestMethod.POST)
 public String uploadFiles(
     User user,
     @RemainedPath String path,
     @RequestParam("description") String description,
     @RequestParam("uploadFile") MultipartFile file,
     ModelMap model) {
   try {
     FileEntry fileEntry = new FileEntry();
     if (fileEntry.getFileType().isEditable()) {
       fileEntry.setContent(new String(file.getBytes()));
     } else {
       fileEntry.setContentBytes(file.getBytes());
     }
     fileEntry.setDescription(description);
     fileEntry.setPath(
         FilenameUtils.separatorsToUnix(FilenameUtils.concat(path, file.getOriginalFilename())));
     fileEntryService.save(user, fileEntry);
     return "redirect:/script/list/" + path;
   } catch (IOException e) {
     LOG.error("Error while getting file content:" + e.getMessage(), e);
     throw new NGrinderRuntimeException("Error while getting file content:" + e.getMessage(), e);
   }
 }