Java 类org.springframework.web.bind.annotation.RequestPart 实例源码

项目:spring-boot-sandbox    文件:DemoApplication.java   
@PostMapping("/")
@ResponseBody
ResponseEntity<StreamingResponseBody> post(@RequestPart final MultipartFile file)
        throws Exception {

    if (file.isEmpty()) {
        throw new ValidationException("file was empty");
    }

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentDispositionFormData("filename", "sample.txt");

    final StreamingResponseBody body = out -> out.write(file.getBytes());

    return ResponseEntity.ok()
            .headers(headers)
            .contentType(MediaType.valueOf("application/force-download"))
            .body(body);
}
项目:spring-grow    文件:UtilityController.java   
@RequestMapping(value = "/user/avatar/update", method = RequestMethod.POST, consumes = { "multipart/form-data" })
public @ResponseBody GenericResponseBody userAvatarUpdate(@RequestPart("avatar_data") AvatarRequest avatarRequest,
      @RequestPart("avatar_file") MultipartFile file) {
   User authenticatedUser = new AuthenticationHolder().getAuthenticatedUser();
   User persistentUser = userService.findByPK(authenticatedUser.getId());

   try {
      persistentUser.setPicture(Utility.cropImage(file.getBytes(), avatarRequest.getX().intValue(),
            avatarRequest.getY().intValue(), avatarRequest.getWidth().intValue(),
            avatarRequest.getHeight().intValue(), avatarRequest.getScaleX() == -1 ? true : false,
            avatarRequest.getScaleY() == -1 ? true : false, avatarRequest.getRotate()));
   } catch (BusinessException | IOException e) {
      return new GenericResponseBody(GenericResponseBodyState.ERROR);
   }

   userService.update(persistentUser);

   return new GenericResponseBody(GenericResponseBodyState.SUCCESS);
}
项目:flow-platform    文件:CredentialController.java   
/**
 * @api {patch} /credentials/:name Update
 * @apiParam {String} name Credential name to update
 *
 * @apiParamExample {multipart} RSA-Multipart-Body:
 *  the same as create
 *
 * @apiGroup Credenital
 */
@PatchMapping(path = "/{name}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@WebSecurity(action = Actions.ADMIN_UPDATE)
public Credential update(@PathVariable String name,
                         @RequestParam(name = "detail") String detailJson,
                         @RequestPart(name = "android-file", required = false) MultipartFile androidFile,
                         @RequestPart(name = "p12-files", required = false) MultipartFile[] p12Files,
                         @RequestPart(name = "pp-files", required = false) MultipartFile[] ppFiles) {

    // check name is existed
    if (!credentialService.existed(name)) {
        throw new IllegalParameterException("Credential name does not existed");
    }

    CredentialDetail detail = jsonConverter.getGsonForReader().fromJson(detailJson, CredentialDetail.class);
    return createOrUpdate(name, detail, androidFile, p12Files, ppFiles);
}
项目:spring4-understanding    文件:RequestPartMethodArgumentResolver.java   
/**
 * Supports the following:
 * <ul>
 * <li>annotated with {@code @RequestPart}
 * <li>of type {@link MultipartFile} unless annotated with {@code @RequestParam}
 * <li>of type {@code javax.servlet.http.Part} unless annotated with {@code @RequestParam}
 * </ul>
 */
@Override
public boolean supportsParameter(MethodParameter parameter) {
    if (parameter.hasParameterAnnotation(RequestPart.class)) {
        return true;
    }
    else {
        if (parameter.hasParameterAnnotation(RequestParam.class)){
            return false;
        }
        else if (MultipartFile.class == parameter.getParameterType()) {
            return true;
        }
        else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
            return true;
        }
        else {
            return false;
        }
    }
}
项目:spring4-understanding    文件:RequestPartMethodArgumentResolverTests.java   
@SuppressWarnings("unused")
public void handle(@RequestPart SimpleBean requestPart,
                   @RequestPart(value="requestPart", required=false) SimpleBean namedRequestPart,
                   @Valid @RequestPart("requestPart") SimpleBean validRequestPart,
                   @RequestPart("requestPart") MultipartFile multipartFile,
                   @RequestPart("requestPart") List<MultipartFile> multipartFileList,
                   @RequestPart("requestPart") MultipartFile[] multipartFileArray,
                   int i,
                   MultipartFile multipartFileNotAnnot,
                   Part part,
                   @RequestPart("part") List<Part> partList,
                   @RequestPart("part") Part[] partArray,
                   @RequestParam MultipartFile requestParamAnnot,
                   Optional<MultipartFile> optionalMultipartFile,
                   Optional<Part> optionalPart,
                   @RequestPart("requestPart") Optional<SimpleBean> optionalRequestPart) {
}
项目:spring4-understanding    文件:RequestParamMethodArgumentResolverTests.java   
public void params(@RequestParam(name = "name", defaultValue = "bar") String param1,
        @RequestParam("name") String[] param2,
        @RequestParam("name") Map<?, ?> param3,
        @RequestParam("mfile") MultipartFile param4,
        @RequestParam("mfilelist") List<MultipartFile> param5,
        @RequestParam("mfilearray") MultipartFile[] param6,
        @RequestParam("pfile") Part param7,
        @RequestParam("pfilelist") List<Part> param8,
        @RequestParam("pfilearray") Part[] param9,
        @RequestParam Map<?, ?> param10,
        String stringNotAnnot,
        MultipartFile multipartFileNotAnnot,
        List<MultipartFile> multipartFileList,
        Part part,
        @RequestPart MultipartFile requestPartAnnot,
        @RequestParam("name") String paramRequired,
        @RequestParam(name = "name", required = false) String paramNotRequired,
        @RequestParam("name") Optional<Integer> paramOptional) {
}
项目:mccy-engine    文件:ApiUploadsController.java   
@RequestMapping(value = "/mods", method = RequestMethod.POST)
public UploadModsResponse uploadMods(@RequestPart("files") MultipartFile[] modFiles)
        throws IOException, MccyException {
    LOG.debug("Upload mods provided: {}", modFiles);
    UploadModsResponse response = new UploadModsResponse();

    for (MultipartFile modFile : modFiles) {
        try {
            response.getMods().add(modsService.ingest(modFile));
        } catch (MccyException | IOException e) {
            UploadModsResponse.Failed failed = new UploadModsResponse.Failed();
            failed.setReason(e.getMessage()+"("+e.getClass()+")");
            failed.setFilename(modFile.getOriginalFilename());

            response.addFailed(failed);

            LOG.warn("Failed to ingest {}", e, modFile);
        }
    }

    return response;
}
项目:bacoma    文件:SiteAdminController.java   
@RequestMapping(value = Constants.BASEURL_REST
        + "/static/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addStaticResource(@PathVariable String siteUrl, @RequestPart("file") Part file, @RequestParam String path) {
    String originalFileName = file.getSubmittedFileName();
    if(originalFileName != null) {
        try {
            String fileName = fileSystemUtil.addStaticResource(getSite(siteUrl), path, file.getInputStream());
            logger.debug("Static resource added successful: {}", fileName);
            return Response.ok(fileName);
        } catch (Exception e) {
            return Response.error(e.getMessage());
        }
    } else {
        return Response.error("Empty file.");
    }
}
项目:class-guard    文件:RequestPartMethodArgumentResolver.java   
/**
 * Supports the following:
 * <ul>
 *  <li>Annotated with {@code @RequestPart}
 *  <li>Of type {@link MultipartFile} unless annotated with {@code @RequestParam}.
 *  <li>Of type {@code javax.servlet.http.Part} unless annotated with {@code @RequestParam}.
 * </ul>
 */
public boolean supportsParameter(MethodParameter parameter) {
    if (parameter.hasParameterAnnotation(RequestPart.class)) {
        return true;
    }
    else {
        if (parameter.hasParameterAnnotation(RequestParam.class)){
            return false;
        }
        else if (MultipartFile.class.equals(parameter.getParameterType())) {
            return true;
        }
        else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
            return true;
        }
        else {
            return false;
        }
    }
}
项目:adjule    文件:ProblemsEndpoint.java   
@PreAuthorize("hasRole('ROLE_ADMIN') or hasAuthority('problem_add')")
@RequestMapping(value = "/problems", method = RequestMethod.POST)
public ProblemDetailView addProblem(@RequestPart("problem") ProblemDetailView problemDetailView,
                                    @RequestParam(value = "contentFile",
                                            required = false) MultipartFile contentFile)
        throws FormException, IOException {

    String contentType = null;
    byte[] content = null;
    if (contentFile != null) {
        contentType = contentFile.getContentType();
        content = Base64.getEncoder().encode(contentFile.getBytes());
    }

    problemDetailDao.createProblem(problemDetailView, contentType, content);
    return problemDetailView;
}
项目:adjule    文件:ProblemsEndpoint.java   
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(@problemsEndpoint.getProblemGroupCodes(#problemCode), 'problem_change')")
@RequestMapping(value = "/problems/{problemCode}", method = RequestMethod.PUT)
@CacheEvict(value = "group_problems", allEntries = true)
public ProblemDetailView editProblem(@PathVariable("problemCode") String problemCode,
                                     @RequestPart("problem") ProblemDetailView problemDetailView,
                                     @RequestParam(value = "contentFile", required = false) MultipartFile contentFile)
        throws FormException, IOException {

    String contentType = null;
    byte[] content = null;
    if (contentFile != null) {
        contentType = contentFile.getContentType();
        content = Base64.getEncoder().encode(contentFile.getBytes());
    }

    problemDetailDao.editProblem(problemCode, problemDetailView, contentType, content);
    return problemDetailView;
}
项目:hypersocket-framework    文件:CertificateResourceController.java   
@AuthenticationRequired
@RequestMapping(value = "certificates/pem", method = RequestMethod.POST, produces = { "application/json" })
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public CertificateStatus uploadKey(HttpServletRequest request,
        HttpServletResponse response,
        @RequestPart(value = "file") MultipartFile file,
        @RequestPart(value = "bundle") MultipartFile bundle,
        @RequestPart(value = "key") MultipartFile key,
        @RequestParam(value = "passphrase") String passphrase)
        throws AccessDeniedException, UnauthorizedException,
        SessionTimeoutException {

    return replaceKey(request, response, file, bundle, key, passphrase,
            null);
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:ApiController.java   
@PostMapping(API_BASE_PATH + "/images")
Mono<Void> create(@RequestPart Flux<FilePart> images) {
    return images
        .map(image -> {
            log.info("We will save " + image +
                " to a Reactive database soon!");
            return image;
        })
        .then();
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:ApiController.java   
@PostMapping(API_BASE_PATH + "/images")
Mono<Void> create(@RequestPart Flux<FilePart> images) {
    return images
        .map(image -> {
            log.info("We will save " + image +
                " to a Reactive database soon!");
            return image;
        })
        .then();
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:UploadController.java   
@PostMapping(value = BASE_PATH)
public Mono<String> createFile(
        @RequestPart("file") Flux<FilePart> files,
        @AuthenticationPrincipal Principal principal) {
    return imageService.createImage(files, principal)
        .then(Mono.just("redirect:/"));
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:UploadController.java   
@PostMapping(value = BASE_PATH)
public Mono<String> createFile(
    @RequestPart("file") Flux<FilePart> files,
    @AuthenticationPrincipal Principal principal) {
    return imageService.createImage(files, principal)
        .then(Mono.just("redirect:/"));
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:ApiController.java   
@PostMapping(API_BASE_PATH + "/images")
Mono<Void> create(@RequestPart Flux<FilePart> images) {
    return images
        .map(image -> {
            log.info("We will save " + image +
                " to a Reactive database soon!");
            return image;
        })
        .then();
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:ApiController.java   
@PostMapping(API_BASE_PATH + "/images")
Mono<Void> create(@RequestPart Flux<FilePart> images) {
    return images
        .map(image -> {
            log.info("We will save " + image +
                " to a Reactive database soon!");
            return image;
        })
        .then();
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:ApiController.java   
@PostMapping(API_BASE_PATH + "/images")
Mono<Void> create(@RequestPart Flux<FilePart> images) {
    Hooks.onOperatorDebug();

    return images
        .map(image -> {
            log.info("We will save " + image + " to a Reactive database soon!");
            return image;
        })
        .then();
}
项目:incubator-servicecomb-java-chassis    文件:SpringmvcSwaggerGeneratorContext.java   
@Override
protected void initParameterAnnotationMgr() {
  super.initParameterAnnotationMgr();

  parameterAnnotationMgr.register(CookieValue.class, new CookieValueAnnotationProcessor());
  parameterAnnotationMgr.register(PathVariable.class, new PathVariableAnnotationProcessor());
  parameterAnnotationMgr.register(RequestBody.class, new RequestBodyAnnotationProcessor());
  parameterAnnotationMgr.register(RequestHeader.class, new RequestHeaderAnnotationProcessor());
  parameterAnnotationMgr.register(RequestParam.class, new RequestParamAnnotationProcessor());
  parameterAnnotationMgr.register(RequestAttribute.class, new RequestAttributeAnnotationProcessor());
  parameterAnnotationMgr.register(RequestPart.class, new RequestPartAnnotationProcessor());
}
项目:devops-cstack    文件:ModuleController.java   
@RequestMapping(value = "/{moduleName}/run-script", method = RequestMethod.POST,
        consumes = "multipart/form-data")
public ResponseEntity<?> runScript(@PathVariable String moduleName, @RequestPart("file") MultipartFile file)
        throws ServiceException, CheckException {
    String result = moduleService.runScript(moduleName, file);

    return ResponseEntity.ok(result);
}
项目:devops-cstack    文件:ApplicationController.java   
/**
 * Deploy a web application
 *
 * @return
 * @throws IOException
 * @throws ServiceException
 * @throws CheckException
 */
@ResponseBody
@RequestMapping(value = "/{applicationName}/deploy", method = RequestMethod.POST, consumes = {
        "multipart/form-data" })
public JsonResponse deploy(@RequestPart("file") MultipartFile fileUpload, @PathVariable String applicationName,
        HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServiceException, CheckException {

    logger.info("applicationName = " + applicationName + "file = " + fileUpload.getOriginalFilename());

    User user = authentificationUtils.getAuthentificatedUser();
    Application application = applicationService.findByNameAndUser(user, applicationName);

    // We must be sure there is no running action before starting new one
    authentificationUtils.canStartNewAction(user, application, Locale.ENGLISH);

       application = applicationService.deploy(fileUpload, application);

    String needRestart = dockerService.getEnv(application.getServer().getContainerID(),
            "CU_SERVER_RESTART_POST_DEPLOYMENT");
    if ("true".equalsIgnoreCase(needRestart)){
           // set the application in pending mode
           applicationEventPublisher.publishEvent(new ApplicationPendingEvent(application));
           applicationService.stop(application);
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        applicationService.start(application);
           // wait for modules and servers starting
           applicationEventPublisher.publishEvent(new ApplicationStartEvent(application));
    }

    logger.info("--DEPLOY APPLICATION WAR ENDED--");
    return new HttpOk();
}
项目:devops-cstack    文件:FileController.java   
/**
 * Upload a file into a container
 *
 * @return
 * @throws IOException
 * @throws ServiceException
 * @throws CheckException
 */
@RequestMapping(value = "/container/{containerId}/application/{applicationName}", method = RequestMethod.POST, consumes = {
        "multipart/form-data" })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public JsonResponse uploadFile(@PathVariable final String applicationName,
                                  @RequestPart("file") MultipartFile fileUpload, @PathVariable final String containerId,
                                  @RequestParam("path") String path, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServiceException, CheckException {

    if (logger.isDebugEnabled()) {
        logger.debug("-- CALL UPLOAD FILE TO CONTAINER FS --");
        logger.debug("applicationName = " + applicationName);
        logger.debug("containerId = " + containerId);
        logger.debug("pathFile = " + path);
    }

    User user = authentificationUtils.getAuthentificatedUser();
    Application application = applicationService.findByNameAndUser(user, applicationName);

    // We must be sure there is no running action before starting new one
    this.authentificationUtils.canStartNewAction(user, application, locale);

    try {
        // Application is now pending
        applicationService.setStatus(application, Status.PENDING);

        fileService.sendFileToContainer(containerId, path, fileUpload, null, null);
    } finally {
        // Application is always set to start
        applicationService.setStatus(application, Status.START);
    }

    return new HttpOk();
}
项目:yum    文件:SettingsApiController.java   
@Override
@PreAuthorize("hasAuthority('hungry')")
public ResponseEntity<Void> settingsPicturePost(@ApiParam(value = "file detail") @RequestPart("file") MultipartFile file,
    @ApiParam(value = "Description of file contents." ) @RequestPart(value="userid", required=false)  Integer userid) throws ApiException {
    // do some magic!
    settingsService.PicturePost(file);
    return new ResponseEntity<>(HttpStatus.OK);
}
项目:yum    文件:SettingsApi.java   
@ApiOperation(value = "Uploads a file.", notes = "", response = Void.class, authorizations = {
    @Authorization(value = "Bearer")
}, tags={  })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "Picture set", response = Void.class),
    @ApiResponse(code = 500, message = "An unexpected error occured.", response = Void.class) })
@RequestMapping(value = "/settings/picture",
    produces = { "application/json" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
@CrossOrigin
ResponseEntity<Void> settingsPicturePost(@ApiParam(value = "file detail") @RequestPart("file") MultipartFile upfile,
    @ApiParam(value = "Description of file contents." ) @RequestPart(value="userid", required=false)  Integer userid) throws ApiException;
项目:yum    文件:UsersApi.java   
@ApiOperation(value = "Uploads a file.", notes = "", response = Void.class, authorizations = {
    @Authorization(value = "Bearer")
}, tags={ "admin", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "Picture set", response = Void.class),
    @ApiResponse(code = 500, message = "An unexpected error occured.", response = Void.class) })
@RequestMapping(value = "/users/{id}/picture",
    produces = { "application/json" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
@CrossOrigin 
ResponseEntity<Void> usersIdPicturePost(@ApiParam(value = "user id",required=true ) @PathVariable("id") Integer id,
    @ApiParam(value = "file detail") @RequestPart("file") MultipartFile file)throws ApiException;
项目:xm-ms-entity    文件:XmEntityResource.java   
@PostMapping("/xm-entities/{idOrKey}/links/targets")
@Timed
public ResponseEntity<Link> saveLinkTarget(@PathVariable String idOrKey, @RequestPart("link") Link link,
    @RequestPart(value = "file", required = false) MultipartFile file) {
    log.debug("REST request to create target for entity {}", idOrKey);
    Link result = xmEntityService.saveLinkTarget(IdOrKey.of(idOrKey), link, file);
    return ResponseEntity.ok().body(result);
}
项目:xm-ms-entity    文件:XmEntityResource.java   
@PostMapping("/xm-entities/self/links/targets")
@Timed
public ResponseEntity<Link> saveSelfLinkTarget(@RequestPart("link") Link link,
    @RequestPart(value = "file", required = false) MultipartFile file) {
    log.debug("REST request to create target for self");
    Link result = xmEntityService.saveSelfLinkTarget(link, file);
    return ResponseEntity.ok().body(result);
}
项目:xm-ms-entity    文件:XmEntityResource.java   
@PostMapping("/xm-entities/{idOrKey}/links/targets/{targetId}")
@Timed
public ResponseEntity<Link> updateLinkTarget(@PathVariable String idOrKey, @PathVariable String targetId,
    @RequestPart("link") Link link, @RequestPart(value = "file", required = false) MultipartFile file) {
    log.debug("REST request to update target for entity {}", idOrKey);
    Link result = xmEntityService.updateLinkTarget(IdOrKey.of(idOrKey), targetId, link, file);
    return ResponseEntity.ok().body(result);
}
项目:xm-ms-entity    文件:XmEntityResource.java   
@PostMapping("/xm-entities/self/links/targets/{targetId}")
@Timed
public ResponseEntity<Link> updateSelfLinkTarget(@PathVariable String targetId,
    @RequestPart("link") Link link, @RequestPart(value = "file", required = false) MultipartFile file) {
    log.debug("REST request to update target for self");
    Link result = xmEntityService.updateSelfLinkTarget(targetId, link, file);
    return ResponseEntity.ok().body(result);
}
项目:docker-dash    文件:ConnectionsApi.java   
@ApiOperation(value = "save docker connection to DB", notes = "", response = Void.class, tags={ "Connections", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "OK", response = Void.class),
    @ApiResponse(code = 201, message = "successfully created", response = Void.class) })
@RequestMapping(value = "/connections",
        consumes = {"multipart/form-data"},
        method = RequestMethod.POST)
ResponseEntity<Void> connectionPost(@ApiParam(value = "", required = true) @RequestPart(value = "name", required = true) String name, @ApiParam(value = "", required = true) @RequestPart(value = "address", required = true) String address, @ApiParam(value = "", required = true) @RequestPart(value = "dockerTLSVerify", required = false) String dockerTLSVerify, @ApiParam(value = "") @RequestPart(value = "dockerConfig", required = false) MultipartFile dockerConfig, @ApiParam(value = "") @RequestPart(value = "file", required = false) MultipartFile upfile);
项目:karate    文件:UploadController.java   
@PostMapping("/mixed")
public @ResponseBody FileInfo uploadMixed(@RequestPart("myJson") String json, 
        @RequestPart("myFile") MultipartFile file) throws Exception {
    Message message = mapper.readValue(json, Message.class);
    String text = message.getText();
    return upload(file, text);
}
项目:lams    文件:RequestParamMethodArgumentResolver.java   
/**
 * Supports the following:
 * <ul>
 * <li>@RequestParam-annotated method arguments.
 * This excludes {@link Map} params where the annotation doesn't
 * specify a name.  See {@link RequestParamMapMethodArgumentResolver}
 * instead for such params.
 * <li>Arguments of type {@link MultipartFile}
 * unless annotated with @{@link RequestPart}.
 * <li>Arguments of type {@code javax.servlet.http.Part}
 * unless annotated with @{@link RequestPart}.
 * <li>In default resolution mode, simple type arguments
 * even if not with @{@link RequestParam}.
 * </ul>
 */
@Override
public boolean supportsParameter(MethodParameter parameter) {
    Class<?> paramType = parameter.getParameterType();
    if (parameter.hasParameterAnnotation(RequestParam.class)) {
        if (Map.class.isAssignableFrom(paramType)) {
            String paramName = parameter.getParameterAnnotation(RequestParam.class).value();
            return StringUtils.hasText(paramName);
        }
        else {
            return true;
        }
    }
    else {
        if (parameter.hasParameterAnnotation(RequestPart.class)) {
            return false;
        }
        else if (MultipartFile.class.equals(paramType) || "javax.servlet.http.Part".equals(paramType.getName())) {
            return true;
        }
        else if (this.useDefaultResolution) {
            return BeanUtils.isSimpleProperty(paramType);
        }
        else {
            return false;
        }
    }
}
项目:flow-platform    文件:CmdController.java   
/**
 * Upload zipped cmd log with multipart
 *
 * @param cmdId cmd id with text/plain
 * @param file zipped cmd log with application/zip
 */
@PostMapping(path = "/log/upload")
public void uploadFullLog(@RequestPart String cmdId, @RequestPart MultipartFile file) {
    if (!Objects.equals(file.getContentType(), "application/zip")) {
        throw new IllegalParameterException("Illegal zipped log file format");
    }
    cmdService.saveLog(cmdId, file);
}
项目:loc-framework    文件:LocAccessLogTest.java   
@RequestMapping(value = "/post/multiPart", method = RequestMethod.POST)
@ResponseBody
public String saveAuto(
    @RequestPart(value = "json") JsonPojo pojo,
    @RequestParam(value = "some-random") String random,
    @RequestParam(value = "data", required = false) List<MultipartFile> files) {
  System.out.println(random);
  System.out.println(pojo.getJson());
  for (MultipartFile file : files) {
    System.out.println(file.getOriginalFilename());
  }
  return "success";
}
项目:feign-client-test    文件:ServerMain.java   
@RequestMapping(path = "/uploadArray/{folder}", method = POST)
public HttpEntity<List<UploadInfo>> uploadArray(@PathVariable String folder, @RequestPart MultipartFile[] files, @RequestPart UploadMetadata metadata) {
    List<UploadInfo> response = new ArrayList<>();
    for (MultipartFile file : files) {
        response.add(new UploadInfo(i++, file.getSize(), folder + "/" + file.getOriginalFilename()));
    }
    return ResponseEntity.ok(response);
}
项目:oma-riista-web    文件:ClubAreaApiResource.java   
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/{id:\\d+}/import", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void importGeojson(@PathVariable long id,
                          @RequestPart("file") MultipartFile file) throws IOException {
    if (file.isEmpty()) {
        throw new IllegalArgumentException("Empty upload");
    }

    huntingClubAreaImportFeature.importGeojson(id,
            toFeatureCollection(file.getInputStream(), file.getOriginalFilename()));
}
项目:spring4-understanding    文件:RequestPartMethodArgumentResolver.java   
private String getPartName(MethodParameter methodParam) {
    RequestPart requestPart = methodParam.getParameterAnnotation(RequestPart.class);
    String partName = (requestPart != null ? requestPart.name() : "");
    if (partName.length() == 0) {
        partName = methodParam.getParameterName();
        if (partName == null) {
            throw new IllegalArgumentException("Request part name for argument type [" +
                    methodParam.getNestedParameterType().getName() +
                    "] not specified, and parameter name information not found in class file either.");
        }
    }
    return partName;
}
项目:spring4-understanding    文件:RequestPartIntegrationTests.java   
@RequestMapping(value = "/test", method = POST, consumes = {"multipart/mixed", "multipart/form-data"})
public ResponseEntity<Object> create(@RequestPart(name = "json-data") TestData testData,
        @RequestPart("file-data") Optional<MultipartFile> file,
        @RequestPart(name = "empty-data", required = false) TestData emptyData,
        @RequestPart(name = "iso-8859-1-data") byte[] iso88591Data) {

    Assert.assertArrayEquals(new byte[]{(byte) 0xC4}, iso88591Data);

    String url = "http://localhost:8080/test/" + testData.getName() + "/" + file.get().getOriginalFilename();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(URI.create(url));
    return new ResponseEntity<Object>(headers, HttpStatus.CREATED);
}
项目:spring4-understanding    文件:RequestParamMethodArgumentResolver.java   
/**
 * Supports the following:
 * <ul>
 * <li>@RequestParam-annotated method arguments.
 * This excludes {@link Map} params where the annotation doesn't
 * specify a name.  See {@link RequestParamMapMethodArgumentResolver}
 * instead for such params.
 * <li>Arguments of type {@link MultipartFile}
 * unless annotated with @{@link RequestPart}.
 * <li>Arguments of type {@code javax.servlet.http.Part}
 * unless annotated with @{@link RequestPart}.
 * <li>In default resolution mode, simple type arguments
 * even if not with @{@link RequestParam}.
 * </ul>
 */
@Override
public boolean supportsParameter(MethodParameter parameter) {
    Class<?> paramType = parameter.getParameterType();
    if (parameter.hasParameterAnnotation(RequestParam.class)) {
        if (Map.class.isAssignableFrom(paramType)) {
            String paramName = parameter.getParameterAnnotation(RequestParam.class).name();
            return StringUtils.hasText(paramName);
        }
        else {
            return true;
        }
    }
    else {
        if (parameter.hasParameterAnnotation(RequestPart.class)) {
            return false;
        }
        else if (MultipartFile.class == paramType || "javax.servlet.http.Part".equals(paramType.getName())) {
            return true;
        }
        else if (this.useDefaultResolution) {
            return BeanUtils.isSimpleProperty(paramType);
        }
        else {
            return false;
        }
    }
}