Example #1
0
  @RequestMapping(value = "/uploadFiles")
  @ResponseBody
  public Result uploadFiles(HttpServletRequest request) throws IOException {
    MultipartHttpServletRequest servletRequest = (MultipartHttpServletRequest) request;
    List<MultipartFile> fileList = servletRequest.getFiles("uploadFile");
    if (fileList != null && fileList.size() > 0) {
      List<String> files = new ArrayList<String>();
      for (MultipartFile file : fileList) {
        if (file != null && file.getSize() > 0) {
          String realPath = request.getSession().getServletContext().getRealPath("/upload");
          String remotFilePath = FtpUtil.getFilePathName("file");
          String orgFileName = file.getOriginalFilename();
          String remortFileName = FtpUtil.getRemotFileName(orgFileName);
          String fileName =
              (new StringBuilder())
                  .append(remotFilePath)
                  .append("/")
                  .append(remortFileName)
                  .toString();
          FileUtils.copyInputStreamToFile(
              file.getInputStream(),
              new File(realPath + File.separator + remotFilePath, remortFileName));

          files.add(fileName);
        }
      }
      String dataJson = JSON.toJSONString(files);
      return Result.getSuccessResult(dataJson);
    }
    return new Result(ErrorCode.UPLOAD_FILE_FAILURE);
  }
Example #2
0
 @RequestMapping(value = "/deleteFile")
 @ResponseBody
 public Result deleteFile(@RequestParam("filePath") String filePath) {
   ftpUploader.deleteFile(filePath);
   return Result.getSuccessResult("");
 }