@Override
  public void cleanupMultipart(MultipartHttpServletRequest request) {

    if (request != null) {

      DefaultMultipartHttpServletRequest defaultRequest =
          (DefaultMultipartHttpServletRequest) request;
      RequestWrapper requestWrapper = (RequestWrapper) defaultRequest.getRequest();

      // Call to the original method
      this.cleanupFileItems(getMultipartFileElements(requestWrapper.getFileElements()));
    }
  }
예제 #2
0
  /**
   * 上传文件
   *
   * @param request
   * @param response
   * @throws IOException
   */
  @RequestMapping("upload")
  public void uploadFile(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    Map<String, Object> map = new HashMap<String, Object>();
    if (!(request instanceof DefaultMultipartHttpServletRequest)) {
      return;
    }
    DefaultMultipartHttpServletRequest re = (DefaultMultipartHttpServletRequest) request;
    Map<String, MultipartFile> fileMaps = re.getFileMap();
    Collection<MultipartFile> files = fileMaps.values();
    List<String> fileIds = new ArrayList<String>();
    for (MultipartFile myfile : files) {
      if (myfile.isEmpty()) {
        System.err.println("文件未上传");
      } else {
        String originalName = myfile.getOriginalFilename();
        String extName = FileUtil.getFileExtName(originalName);
        String filePath =
            storageClientService.uploadFile(
                null,
                new ByteArrayInputStream(myfile.getBytes()),
                myfile.getBytes().length,
                extName.toUpperCase());
        SxjLogger.info("siteUploadFilePath=" + filePath, this.getClass());
        fileIds.add(filePath);

        // 上传元数据
        NameValuePair[] metaList = new NameValuePair[1];
        metaList[0] = new NameValuePair("originalName", originalName);
        storageClientService.overwriteMetadata(filePath, metaList);
      }
    }
    map.put("fileIds", fileIds);
    String res = JsonMapper.nonDefaultMapper().toJson(map);
    response.setContentType("text/plain;UTF-8");
    PrintWriter out = response.getWriter();
    out.print(res);
    out.flush();
    out.close();
  }
예제 #3
0
  /**
   * 파일을 업로드한다.
   *
   * @return REST Response JAXB Object
   */
  @RequestMapping(
      value = "/upload",
      method = RequestMethod.POST,
      consumes = {"multipart/form-data"})
  @ResponseStatus(HttpStatus.OK)
  public ResponseEntity<String> upload(HttpServletRequest req) throws IOException {
    Response response = new Response();

    if (!(req instanceof DefaultMultipartHttpServletRequest)) {
      response.setSuccess(false);
      response.getError().setCause("Invalid Request.");
      response.getError().setMessage("Invalid Request.");
      String json = new ObjectMapper().writeValueAsString(response);
      return new ResponseEntity(json, HttpStatus.BAD_REQUEST);
    }

    try {
      DefaultMultipartHttpServletRequest request = (DefaultMultipartHttpServletRequest) req;
      logger.debug(
          "Uploaded File >> Path : {}, Filename : {}, Size: {} bytes",
          new Object[] {
            request.getParameter("path"),
            request.getFile("file").getOriginalFilename(),
            request.getFile("file").getSize()
          });

      String clusterName = request.getParameter("clusterName");
      Map params = new HashMap();

      EngineService engineService = this.getEngineService(clusterName);
      VisualService service = engineService.getVisualService();
      Map resultMap = service.saveFile(request.getFile("file"), request.getParameter("options"));

      response.getMap().putAll(resultMap);
      response.setSuccess(true);
      String json = new ObjectMapper().writeValueAsString(response);
      HttpStatus statusCode = HttpStatus.OK;
      return new ResponseEntity(json, statusCode);
    } catch (Exception ex) {
      response.setSuccess(false);
      response.getError().setMessage(ex.getMessage());
      if (ex.getCause() != null) response.getError().setCause(ex.getCause().getMessage());
      response.getError().setException(ExceptionUtils.getFullStackTrace(ex));

      String json = new ObjectMapper().writeValueAsString(response);
      HttpStatus statusCode = HttpStatus.INTERNAL_SERVER_ERROR;

      logger.debug(ExceptionUtils.getFullStackTrace(ex));

      return new ResponseEntity(json, statusCode);
    }
  }
예제 #4
0
  @RequestMapping(value = IMAGES, method = POST)
  public String addImage(
      @RequestParam("image") MultipartFile file,
      DefaultMultipartHttpServletRequest request,
      Locale locale)
      throws IOException {

    // NOTE: Checking user rights and CSRF-Token needs to be done here because HttpUserService gains
    // NOTE org.eclipse.jetty.server.Request which is not able to handle parameters at
    // multipartrequests

    User currentUser = userService.getCurrentUser(false);
    if (!currentUser.isOm()) {
      throw new AccessDeniedException("Om rights required");
    }

    userService.verifyCSRFToken(request);

    imageFinder.validateAndSaveFile(file);
    return redirectWithMessage(
        request.getHeader("Referer"), RequestMessage.EDITOR_UPLOAD_IMAGE, request);
  }
예제 #5
0
 public PlaceMenu(DefaultMultipartHttpServletRequest dmhsRequest) {
   this.menuName = dmhsRequest.getParameter("menuName");
   this.menuDescription = dmhsRequest.getParameter("menuDescription");
   this.menuPrice = Integer.valueOf(dmhsRequest.getParameter("menuPrice"));
 }