org.springframework.http.codec.multipart.FormFieldPart Java Examples
The following examples show how to use
org.springframework.http.codec.multipart.FormFieldPart.
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 File: MultipartIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
public Mono<ServerResponse> multipartData(ServerRequest request) { return request .body(BodyExtractors.toMultipartData()) .flatMap(map -> { Map<String, Part> parts = map.toSingleValueMap(); try { assertEquals(2, parts.size()); assertEquals("foo.txt", ((FilePart) parts.get("fooPart")).filename()); assertEquals("bar", ((FormFieldPart) parts.get("barPart")).value()); } catch(Exception e) { return Mono.error(e); } return ServerResponse.ok().build(); }); }
Example #2
Source File: MultipartIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@PostMapping("/requestPart") void requestPart( @RequestPart FormFieldPart fieldPart, @RequestPart("fileParts") FilePart fileParts, @RequestPart("fileParts") Mono<FilePart> filePartsMono, @RequestPart("fileParts") Flux<FilePart> filePartsFlux, @RequestPart("jsonPart") Person person, @RequestPart("jsonPart") Mono<Person> personMono) { assertEquals("fieldValue", fieldPart.value()); assertEquals("fileParts:foo.txt", partDescription(fileParts)); assertEquals("Jason", person.getName()); StepVerifier.create(partFluxDescription(filePartsFlux)) .consumeNextWith(content -> assertEquals("[fileParts:foo.txt,fileParts:logo.png]", content)) .verifyComplete(); StepVerifier.create(filePartsMono) .consumeNextWith(filePart -> assertEquals("fileParts:foo.txt", partDescription(filePart))) .verifyComplete(); StepVerifier.create(personMono) .consumeNextWith(p -> assertEquals("Jason", p.getName())) .verifyComplete(); }
Example #3
Source File: InfluxProxyHandler.java From influx-proxy with Apache License 2.0 | 5 votes |
private static void addBindValue(Map<String, Object> params, String key, List<?> values) { if (!CollectionUtils.isEmpty(values)) { values = values.stream() .map(value -> value instanceof FormFieldPart ? ((FormFieldPart) value).value() : value) .collect(Collectors.toList()); params.put(key, values.size() == 1 ? values.get(0) : values); } }
Example #4
Source File: MultipartIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
public Mono<ServerResponse> multipartData(ServerRequest request) { return request .body(BodyExtractors.toMultipartData()) .flatMap(map -> { Map<String, Part> parts = map.toSingleValueMap(); try { assertEquals(2, parts.size()); assertEquals("foo.txt", ((FilePart) parts.get("fooPart")).filename()); assertEquals("bar", ((FormFieldPart) parts.get("barPart")).value()); } catch(Exception e) { return Mono.error(e); } return ServerResponse.ok().build(); }); }
Example #5
Source File: MultipartIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
public Mono<ServerResponse> parts(ServerRequest request) { return request.body(BodyExtractors.toParts()).collectList() .flatMap(parts -> { try { assertEquals(2, parts.size()); assertEquals("foo.txt", ((FilePart) parts.get(0)).filename()); assertEquals("bar", ((FormFieldPart) parts.get(1)).value()); } catch(Exception e) { return Mono.error(e); } return ServerResponse.ok().build(); }); }
Example #6
Source File: MultipartIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@PostMapping("/requestPart") void requestPart(@RequestPart FormFieldPart fieldPart, @RequestPart("fileParts") FilePart fileParts, @RequestPart("jsonPart") Mono<Person> personMono) { assertEquals("fieldValue", fieldPart.value()); assertEquals("fileParts:foo.txt", partDescription(fileParts)); StepVerifier.create(personMono) .consumeNextWith(p -> assertEquals("Jason", p.getName())) .verifyComplete(); }
Example #7
Source File: WebExchangeDataBinder.java From spring-analysis-note with MIT License | 5 votes |
private static void addBindValue(Map<String, Object> params, String key, List<?> values) { if (!CollectionUtils.isEmpty(values)) { values = values.stream() .map(value -> value instanceof FormFieldPart ? ((FormFieldPart) value).value() : value) .collect(Collectors.toList()); params.put(key, values.size() == 1 ? values.get(0) : values); } }
Example #8
Source File: MultipartIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
public Mono<ServerResponse> parts(ServerRequest request) { return request.body(BodyExtractors.toParts()).collectList() .flatMap(parts -> { try { assertEquals(2, parts.size()); assertEquals("foo.txt", ((FilePart) parts.get(0)).filename()); assertEquals("bar", ((FormFieldPart) parts.get(1)).value()); } catch(Exception e) { return Mono.error(e); } return ServerResponse.ok().build(); }); }
Example #9
Source File: WebExchangeDataBinder.java From java-technology-stack with MIT License | 5 votes |
private static void addBindValue(Map<String, Object> params, String key, List<?> values) { if (!CollectionUtils.isEmpty(values)) { values = values.stream() .map(value -> value instanceof FormFieldPart ? ((FormFieldPart) value).value() : value) .collect(Collectors.toList()); params.put(key, values.size() == 1 ? values.get(0) : values); } }
Example #10
Source File: FunctionController.java From spring-cloud-function with Apache License 2.0 | 5 votes |
private MultiValueMap<String, String> multi(MultiValueMap<String, Part> body) { MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); for (String key : body.keySet()) { for (Part part : body.get(key)) { if (part instanceof FormFieldPart) { FormFieldPart form = (FormFieldPart) part; map.add(key, form.value()); } } } return map; }
Example #11
Source File: MultipartIntegrationTests.java From spring-analysis-note with MIT License | 4 votes |
private void assertBarPart(Part part) { assertEquals("barPart", part.name()); assertTrue(part instanceof FormFieldPart); assertEquals("bar", ((FormFieldPart) part).value()); }
Example #12
Source File: MultipartIntegrationTests.java From java-technology-stack with MIT License | 4 votes |
private void assertBarPart(Part part) { assertEquals("barPart", part.name()); assertTrue(part instanceof FormFieldPart); assertEquals("bar", ((FormFieldPart) part).value()); }