Java Code Examples for org.springframework.web.bind.annotation.RequestPart

The following examples show how to use org.springframework.web.bind.annotation.RequestPart. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: openapi-generator   Source File: PetApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * POST /pet/{petId}/uploadImage : uploads an image
 *
 * @param petId ID of pet to update (required)
 * @param additionalMetadata Additional data to pass to server (optional)
 * @param file file to upload (optional)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "uploads an image", nickname = "uploadFile", notes = "", response = ModelApiResponse.class, authorizations = {
    @Authorization(value = "petstore_auth", scopes = {
        @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
        @AuthorizationScope(scope = "read:pets", description = "read your pets")
        })
}, tags={ "pet", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
@RequestMapping(value = "/pet/{petId}/uploadImage",
    produces = "application/json", 
    consumes = "multipart/form-data",
    method = RequestMethod.POST)
default ResponseEntity<ModelApiResponse> uploadFile(@ApiParam(value = "ID of pet to update",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "Additional data to pass to server") @Valid @RequestPart(value = "additionalMetadata", required = false)  String additionalMetadata,@ApiParam(value = "file to upload") @Valid @RequestPart(value = "file", required = false) MultipartFile file) {
    getRequest().ifPresent(request -> {
        for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
            if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
                String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }";
                ApiUtil.setExampleResponse(request, "application/json", exampleString);
                break;
            }
        }
    });
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

}
 
Example 2
Source Project: Spring   Source File: UploadController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * curl -F [email protected]/home/olinnyk/IdeaProjects/Spring/SpringWEB/SpringBoot/just-gif-it/video/PexelsVideos.mp4 -F start=0 -F end=5 -F speed=1 -F repeat=0 localhost:8080/upload
 */
@PostMapping
@RequestMapping(value = "/upload", produces = MediaType.IMAGE_GIF_VALUE)
public String upload(@RequestPart("file") MultipartFile file,
		@RequestParam("start") int start,
		@RequestParam("end") int end,
		@RequestParam("speed") int speed,
		@RequestParam("repeat") boolean repeat) throws IOException, FrameGrabber.Exception {

	final File videoFile = new File(location + "/" + System.currentTimeMillis() + ".mp4");
	file.transferTo(videoFile);

	log.info("Saved video file to {}", videoFile.getAbsolutePath());

	final Path output = Paths.get(location + "/gif/" + System.currentTimeMillis() + ".gif");

	final FFmpegFrameGrabber frameGrabber = videoDecoderService.read(videoFile);
	final AnimatedGifEncoder gifEncoder = gifEncoderService.getGifEncoder(repeat, (float) frameGrabber.getFrameRate(), output);
	converterService.toAnimatedGif(frameGrabber, gifEncoder, start, end, speed);

	log.info("Saved generated gif to {}", output.toString());

	return output.getFileName().toString();
}
 
Example 3
Source Project: openapi-generator   Source File: PetApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * POST /pet/{petId}/uploadImage : uploads an image
 *
 * @param petId ID of pet to update (required)
 * @param additionalMetadata Additional data to pass to server (optional)
 * @param file file to upload (optional)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "uploads an image", nickname = "uploadFile", notes = "", response = ModelApiResponse.class, authorizations = {
    @Authorization(value = "petstore_auth", scopes = {
        @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
        @AuthorizationScope(scope = "read:pets", description = "read your pets")
        })
}, tags={ "pet", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
@RequestMapping(value = "/pet/{petId}/uploadImage",
    produces = { "application/json" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
default ResponseEntity<ModelApiResponse> uploadFile(@ApiParam(value = "ID of pet to update",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "Additional data to pass to server") @Valid @RequestPart(value = "additionalMetadata", required = false)  String additionalMetadata,@ApiParam(value = "file to upload") @Valid @RequestPart(value = "file", required = false) MultipartFile file) {
    getRequest().ifPresent(request -> {
        for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
            if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
                String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }";
                ApiUtil.setExampleResponse(request, "application/json", exampleString);
                break;
            }
        }
    });
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

}
 
Example 4
Source Project: openapi-generator   Source File: PetApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * POST /pet/{petId}/uploadImage : uploads an image
 *
 * @param petId ID of pet to update (required)
 * @param additionalMetadata Additional data to pass to server (optional)
 * @param file file to upload (optional)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "uploads an image", nickname = "uploadFile", notes = "", response = ModelApiResponse.class, authorizations = {
    @Authorization(value = "petstore_auth", scopes = {
        @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
        @AuthorizationScope(scope = "read:pets", description = "read your pets")
        })
}, tags={ "pet", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
@RequestMapping(value = "/pet/{petId}/uploadImage",
    produces = { "application/json" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
default ResponseEntity<ModelApiResponse> uploadFile(@ApiParam(value = "ID of pet to update",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "Additional data to pass to server") @Valid @RequestPart(value = "additionalMetadata", required = false)  String additionalMetadata,@ApiParam(value = "file to upload") @Valid @RequestPart(value = "file", required = false) MultipartFile file) {
    getRequest().ifPresent(request -> {
        for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
            if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
                String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }";
                ApiUtil.setExampleResponse(request, "application/json", exampleString);
                break;
            }
        }
    });
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

}
 
Example 5
Source Project: swagger-aem   Source File: SlingApi.java    License: Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "", notes = "", response = KeystoreInfo.class, authorizations = {
    @Authorization(value = "aemAuth")
}, tags={ "sling", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "Retrieved Authorizable Keystore info", response = KeystoreInfo.class),
    @ApiResponse(code = 200, message = "Default response", response = String.class) })
@RequestMapping(value = "/{intermediatePath}/{authorizableId}.ks.html",
    produces = { "text/plain" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
ResponseEntity<KeystoreInfo> postAuthorizableKeystore(@ApiParam(value = "",required=true ) @PathVariable("intermediatePath") String intermediatePath,@ApiParam(value = "",required=true ) @PathVariable("authorizableId") String authorizableId,@ApiParam(value = "")  @RequestParam(value = ":operation", required = false) String colonOperation,@ApiParam(value = "")  @RequestParam(value = "currentPassword", required = false) String currentPassword,@ApiParam(value = "")  @RequestParam(value = "newPassword", required = false) String newPassword,@ApiParam(value = "")  @RequestParam(value = "rePassword", required = false) String rePassword,@ApiParam(value = "")  @RequestParam(value = "keyPassword", required = false) String keyPassword,@ApiParam(value = "")  @RequestParam(value = "keyStorePass", required = false) String keyStorePass,@ApiParam(value = "")  @RequestParam(value = "alias", required = false) String alias,@ApiParam(value = "")  @RequestParam(value = "newAlias", required = false) String newAlias,@ApiParam(value = "")  @RequestParam(value = "removeAlias", required = false) String removeAlias,@ApiParam(value = "file detail")  @RequestPart("file") MultipartFile cert-chain,@ApiParam(value = "file detail")  @RequestPart("file") MultipartFile pk,@ApiParam(value = "file detail")  @RequestPart("file") MultipartFile keyStore, @RequestHeader(value = "Accept", required = false) String accept) throws Exception;


@ApiOperation(value = "", notes = "", response = String.class, authorizations = {
    @Authorization(value = "aemAuth")
}, tags={ "sling", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "Default response", response = String.class) })
@RequestMapping(value = "/libs/granite/security/post/authorizables",
    produces = { "text/html" }
 
Example 6
Source Project: swagger-aem   Source File: IntermediatePathApi.java    License: Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "", nickname = "postAuthorizableKeystore", notes = "", response = KeystoreInfo.class, authorizations = {
        @Authorization(value = "aemAuth")
    }, tags={ "sling", })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "Retrieved Authorizable Keystore info", response = KeystoreInfo.class),
        @ApiResponse(code = 200, message = "Default response", response = String.class) })
    @RequestMapping(value = "/{intermediatePath}/{authorizableId}.ks.html",
        produces = { "text/plain" }, 
        consumes = { "multipart/form-data" },
        method = RequestMethod.POST)
    default ResponseEntity<KeystoreInfo> postAuthorizableKeystore(@ApiParam(value = "",required=true) @PathVariable("intermediatePath") String intermediatePath,@ApiParam(value = "",required=true) @PathVariable("authorizableId") String authorizableId,@ApiParam(value = "") @Valid @RequestParam(value = ":operation", required = false) String colonOperation,@ApiParam(value = "") @Valid @RequestParam(value = "currentPassword", required = false) String currentPassword,@ApiParam(value = "") @Valid @RequestParam(value = "newPassword", required = false) String newPassword,@ApiParam(value = "") @Valid @RequestParam(value = "rePassword", required = false) String rePassword,@ApiParam(value = "") @Valid @RequestParam(value = "keyPassword", required = false) String keyPassword,@ApiParam(value = "") @Valid @RequestParam(value = "keyStorePass", required = false) String keyStorePass,@ApiParam(value = "") @Valid @RequestParam(value = "alias", required = false) String alias,@ApiParam(value = "") @Valid @RequestParam(value = "newAlias", required = false) String newAlias,@ApiParam(value = "") @Valid @RequestParam(value = "removeAlias", required = false) String removeAlias,@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile cert-chain,@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile pk,@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile keyStore) {
        getRequest().ifPresent(request -> {
            for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
                if (mediaType.isCompatibleWith(MediaType.valueOf(""))) {
                    ApiUtil.setExampleResponse(request, "", "");
                    break;
                }
            }
        });
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

    }

}
 
Example 7
Source Project: openapi-generator   Source File: PetApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * POST /pet/{petId} : Updates a pet in the store with form data
 *
 * @param petId ID of pet that needs to be updated (required)
 * @param name Updated name of the pet (optional)
 * @param status Updated status of the pet (optional)
 * @return Invalid input (status code 405)
 */
@ApiOperation(value = "Updates a pet in the store with form data", nickname = "updatePetWithForm", notes = "", authorizations = {
    @Authorization(value = "petstore_auth", scopes = {
        @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
        @AuthorizationScope(scope = "read:pets", description = "read your pets")
        })
}, tags={ "pet", })
@ApiResponses(value = { 
    @ApiResponse(code = 405, message = "Invalid input") })
@RequestMapping(value = "/pet/{petId}",
    consumes = { "application/x-www-form-urlencoded" },
    method = RequestMethod.POST)
default ResponseEntity<Void> updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "Updated name of the pet") @Valid @RequestPart(value = "name", required = false)  String name,@ApiParam(value = "Updated status of the pet") @Valid @RequestPart(value = "status", required = false)  String status) {
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

}
 
Example 8
Source Project: openapi-generator   Source File: FakeApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required)
 *
 * @param petId ID of pet to update (required)
 * @param requiredFile file to upload (required)
 * @param additionalMetadata Additional data to pass to server (optional)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "uploads an image (required)", nickname = "uploadFileWithRequiredFile", notes = "", response = ModelApiResponse.class, authorizations = {
    @Authorization(value = "petstore_auth", scopes = {
        @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
        @AuthorizationScope(scope = "read:pets", description = "read your pets")
        })
}, tags={ "pet", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
@RequestMapping(value = "/fake/{petId}/uploadImageWithRequiredFile",
    produces = { "application/json" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
default ResponseEntity<ModelApiResponse> uploadFileWithRequiredFile(@ApiParam(value = "ID of pet to update",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "file to upload") @Valid @RequestPart(value = "requiredFile", required = true) MultipartFile requiredFile,@ApiParam(value = "Additional data to pass to server") @Valid @RequestPart(value = "additionalMetadata", required = false)  String additionalMetadata) {
    return getDelegate().uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata);
}
 
Example 9
Source Project: feign-form   Source File: Server.java    License: Apache License 2.0 5 votes vote down vote up
@PostMapping(path = "/upload/unknown_type", consumes = MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<String> uploadUnknownType (@RequestPart("file") MultipartFile file) {
  val status = file != null
               ? OK
               : I_AM_A_TEAPOT;
  return ResponseEntity.status(status).body(file.getContentType());
}
 
Example 10
Source Project: halo   Source File: MigrateController.java    License: GNU General Public License v3.0 5 votes vote down vote up
@PostMapping("halo")
@ApiOperation("Migrate from Halo")
public void migrateHalo(@RequestPart("file") MultipartFile file) {
    if (optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false)) {
        throw new BadRequestException("无法在博客初始化完成之后迁移数据");
    }
    migrateService.migrate(file, MigrateType.HALO);
}
 
Example 11
Source Project: feign-form   Source File: Server.java    License: Apache License 2.0 5 votes vote down vote up
@PostMapping(path = "/upload/with_dto", consumes = MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Long> uploadWithDto (Dto dto, @RequestPart("file") MultipartFile file
) throws IOException {
  val status = dto != null && dto.getName().equals("Artem")
               ? OK
               : I_AM_A_TEAPOT;
  return ResponseEntity.status(status).body(file.getSize());
}
 
Example 12
Source Project: openapi-generator   Source File: PetApi.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * POST /pet/{petId} : Updates a pet in the store with form data
 *
 * @param petId ID of pet that needs to be updated (required)
 * @param name Updated name of the pet (optional)
 * @param status Updated status of the pet (optional)
 * @return Invalid input (status code 405)
 */
@ApiOperation(value = "Updates a pet in the store with form data", nickname = "updatePetWithForm", notes = "", authorizations = {
    @Authorization(value = "petstore_auth", scopes = {
        @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
        @AuthorizationScope(scope = "read:pets", description = "read your pets")
        })
}, tags={ "pet", })
@ApiResponses(value = { 
    @ApiResponse(code = 405, message = "Invalid input") })
@RequestMapping(value = "/pet/{petId}",
    consumes = { "application/x-www-form-urlencoded" },
    method = RequestMethod.POST)
default Mono<ResponseEntity<Void>> updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "Updated name of the pet") @Valid @RequestPart(value = "name", required = false)  String name,@ApiParam(value = "Updated status of the pet") @Valid @RequestPart(value = "status", required = false)  String status, ServerWebExchange exchange) {
    return getDelegate().updatePetWithForm(petId, name, status, exchange);
}
 
Example 13
private String getPartName(MethodParameter methodParam, @Nullable RequestPart requestPart) {
	String partName = (requestPart != null ? requestPart.name() : "");
	if (partName.isEmpty()) {
		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;
}
 
Example 14
@SuppressWarnings("unused")
void handle(
		@RequestPart("name") Person person,
		@RequestPart("name") Mono<Person> personMono,
		@RequestPart("name") Flux<Person> personFlux,
		@RequestPart("name") List<Person> personList,
		@RequestPart("name") Part part,
		@RequestPart("name") Mono<Part> partMono,
		@RequestPart("name") Flux<Part> partFlux,
		@RequestPart("name") List<Part> partList,
		@RequestPart(name = "anotherPart", required = false) Person anotherPerson,
		@RequestPart(name = "anotherPart", required = false) Part anotherPart,
		Person notAnnotated) {}
 
Example 15
@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();
}
 
Example 16
private String getPartName(MethodParameter methodParam, @Nullable RequestPart requestPart) {
	String partName = (requestPart != null ? requestPart.name() : "");
	if (partName.isEmpty()) {
		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;
}
 
Example 17
Source Project: openapi-generator   Source File: FakeApi.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required)
 *
 * @param petId ID of pet to update (required)
 * @param requiredFile file to upload (required)
 * @param additionalMetadata Additional data to pass to server (optional)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "uploads an image (required)", nickname = "uploadFileWithRequiredFile", notes = "", response = ModelApiResponse.class, authorizations = {
    @Authorization(value = "petstore_auth", scopes = {
        @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
        @AuthorizationScope(scope = "read:pets", description = "read your pets")
        })
}, tags={ "pet", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
@RequestMapping(value = "/fake/{petId}/uploadImageWithRequiredFile",
    produces = { "application/json" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
ResponseEntity<ModelApiResponse> uploadFileWithRequiredFile(@ApiParam(value = "ID of pet to update",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "file to upload") @Valid @RequestPart(value = "requiredFile", required = true) MultipartFile requiredFile,@ApiParam(value = "Additional data to pass to server") @Valid @RequestPart(value = "additionalMetadata", required = false)  String additionalMetadata);
 
Example 18
Source Project: feign-form   Source File: Server.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(
    path = "/multipart/upload1/{folder}",
    method = POST,
    consumes = MULTIPART_FORM_DATA_VALUE
)
@SneakyThrows
public String upload1 (@PathVariable("folder") String folder,
                       @RequestPart MultipartFile file,
                       @RequestParam(value = "message", required = false) String message
) {
  return new String(file.getBytes()) + ':' + message + ':' + folder;
}
 
Example 19
Source Project: swagger-aem   Source File: SlingApiController.java    License: Apache License 2.0 5 votes vote down vote up
public ResponseEntity<String> postTruststore(@ApiParam(value = "")  @RequestParam(value = ":operation", required = false) String colonOperation,
    @ApiParam(value = "")  @RequestParam(value = "newPassword", required = false) String newPassword,
    @ApiParam(value = "")  @RequestParam(value = "rePassword", required = false) String rePassword,
    @ApiParam(value = "")  @RequestParam(value = "keyStoreType", required = false) String keyStoreType,
    @ApiParam(value = "")  @RequestParam(value = "removeAlias", required = false) String removeAlias,
    @ApiParam(value = "file detail")  @RequestPart("file") MultipartFile certificate,
    @RequestHeader(value = "Accept", required = false) String accept) throws Exception {
    // do some magic!
    return new ResponseEntity<String>(HttpStatus.OK);
}
 
Example 20
Source Project: spring-analysis-note   Source File: MultipartControllerTests.java    License: MIT License 5 votes vote down vote up
@RequestMapping(value = "/optionalfile", method = RequestMethod.POST)
public String processOptionalFile(@RequestParam Optional<MultipartFile> file,
		@RequestPart Map<String, String> json, Model model) throws IOException {

	if (file.isPresent()) {
		model.addAttribute("fileContent", file.get().getBytes());
	}
	model.addAttribute("jsonContent", json);

	return "redirect:/index";
}
 
Example 21
Source Project: spring-analysis-note   Source File: MultipartControllerTests.java    License: MIT License 5 votes vote down vote up
@RequestMapping(value = "/optionalfilearray", method = RequestMethod.POST)
public String processOptionalFileArray(@RequestParam Optional<MultipartFile[]> file,
		@RequestPart Map<String, String> json, Model model) throws IOException {

	if (file.isPresent()) {
		byte[] content = file.get()[0].getBytes();
		Assert.assertArrayEquals(content, file.get()[1].getBytes());
		model.addAttribute("fileContent", content);
	}
	model.addAttribute("jsonContent", json);

	return "redirect:/index";
}
 
Example 22
Source Project: spring-analysis-note   Source File: MultipartControllerTests.java    License: MIT License 5 votes vote down vote up
@RequestMapping(value = "/part", method = RequestMethod.POST)
public String processPart(@RequestParam Part part,
		@RequestPart Map<String, String> json, Model model) throws IOException {

	model.addAttribute("fileContent", part.getInputStream());
	model.addAttribute("jsonContent", json);

	return "redirect:/index";
}
 
Example 23
Source Project: openapi-generator   Source File: FakeApi.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * GET /fake/jsonFormData : test json serialization of form data
 *
 * @param param field1 (required)
 * @param param2 field2 (required)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "test json serialization of form data", nickname = "testJsonFormData", notes = "", tags={ "fake", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation") })
@RequestMapping(value = "/fake/jsonFormData",
    consumes = { "application/x-www-form-urlencoded" },
    method = RequestMethod.GET)
default ResponseEntity<Void> testJsonFormData(@ApiParam(value = "field1", required=true) @Valid @RequestPart(value = "param", required = true)  String param,@ApiParam(value = "field2", required=true) @Valid @RequestPart(value = "param2", required = true)  String param2) {
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

}
 
Example 24
@RequestMapping(method = RequestMethod.POST, path = "/multipart",
		consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
		produces = MediaType.TEXT_PLAIN_VALUE)
String multipart(@RequestPart("hello") String hello,
		@RequestPart("world") String world,
		@RequestPart("file") MultipartFile file) {
	return hello + world + file.getOriginalFilename();
}
 
Example 25
Source Project: find   Source File: CustomizationAdminController.java    License: MIT License 5 votes vote down vote up
@RequestMapping(value = TYPED_ASSETS_PATH, method = RequestMethod.PUT)
public ResponseEntity<Status> putLogo(
    @PathVariable("type") final AssetType assetType,
    @RequestPart("file") final MultipartFile file
) throws CustomizationException {
    return saveLogo(assetType, file, true);
}
 
Example 26
Source Project: springdoc-openapi   Source File: PetApi.java    License: Apache License 2.0 5 votes vote down vote up
@Operation(summary = "uploads an image", description = "", security = {
		@SecurityRequirement(name = "petstore_auth", scopes = { "write:pets", "read:pets" }) }, tags = { "pet" })
@ApiResponses(value = {
		@ApiResponse(responseCode = "200", description = "successful operation", content = @Content(schema = @Schema(implementation = ModelApiResponse.class))) })
@PostMapping(value = "/pet/{petId}/uploadImage", produces = { "application/json" }, consumes = {
		"multipart/form-data" })
default ResponseEntity<ModelApiResponse> uploadFile(
		@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") Long petId,
		@Parameter(description = "Additional data to pass to server") @RequestParam(value = "additionalMetadata", required = false) String additionalMetadata,
		@Parameter(description = "file detail") @Valid @RequestPart("file") MultipartFile file) {
	return getDelegate().uploadFile(petId, additionalMetadata, file);
}
 
Example 27
Source Project: springdoc-openapi   Source File: HelloController.java    License: Apache License 2.0 5 votes vote down vote up
@PostMapping(value = "/test/103", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(
		requestBody = @RequestBody(
				content = @Content(
						encoding = @Encoding(name = "body", contentType = "application/json")
				)
		)
)
public String postMyRequestBody(
		@RequestPart("body") ExampleBody body,
		@RequestParam("file") MultipartFile file
) {
	return null;
}
 
Example 28
private String getPartName(MethodParameter methodParam, RequestPart requestPart) {
	String partName = (requestPart != null ? requestPart.name() : "");
	if (partName.isEmpty()) {
		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;
}
 
Example 29
Source Project: openapi-generator   Source File: FakeApi.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * GET /fake/jsonFormData : test json serialization of form data
 *
 * @param param field1 (required)
 * @param param2 field2 (required)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "test json serialization of form data", nickname = "testJsonFormData", notes = "", tags={ "fake", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation") })
@RequestMapping(value = "/fake/jsonFormData",
    consumes = { "application/x-www-form-urlencoded" },
    method = RequestMethod.GET)
ResponseEntity<Void> testJsonFormData(@ApiParam(value = "field1", required=true) @Valid @RequestPart(value = "param", required = true)  String param,@ApiParam(value = "field2", required=true) @Valid @RequestPart(value = "param2", required = true)  String param2);
 
Example 30
Source Project: openapi-generator   Source File: FakeApi.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required)
 *
 * @param petId ID of pet to update (required)
 * @param requiredFile file to upload (required)
 * @param additionalMetadata Additional data to pass to server (optional)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "uploads an image (required)", nickname = "uploadFileWithRequiredFile", notes = "", response = ModelApiResponse.class, authorizations = {
    @Authorization(value = "petstore_auth", scopes = {
        @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
        @AuthorizationScope(scope = "read:pets", description = "read your pets")
        })
}, tags={ "pet", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
@RequestMapping(value = "/fake/{petId}/uploadImageWithRequiredFile",
    produces = { "application/json" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
ResponseEntity<ModelApiResponse> uploadFileWithRequiredFile(@ApiParam(value = "ID of pet to update",required=true) @PathVariable("petId") Long petId,@ApiParam(value = "file to upload") @Valid @RequestPart(value = "requiredFile", required = true) MultipartFile requiredFile,@ApiParam(value = "Additional data to pass to server") @Valid @RequestPart(value = "additionalMetadata", required = false)  String additionalMetadata);