Skip to content

Commit dc8498b

Browse files
committed
Refine multipart-forms.adoc
See spring-projectsgh-36094
1 parent 9abe4b4 commit dc8498b

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

framework-docs/modules/ROOT/pages/web/webflux/controller/ann-methods/multipart-forms.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Kotlin::
4141
[source,kotlin,indent=0,subs="verbatim,quotes"]
4242
----
4343
class MyForm(
44-
val name: String,
45-
val file: FilePart)
44+
private val name: String,
45+
private val file: FilePart)
4646
4747
@Controller
4848
class FileUploadController {
@@ -104,7 +104,7 @@ Kotlin::
104104
----
105105
@PostMapping("/")
106106
fun handle(@RequestPart("meta-data") metadata: Part, // <1>
107-
@RequestPart("file-data") file: FilePart): String { // <2>
107+
@RequestPart("file-data") file: FilePart): String { // <2>
108108
// ...
109109
}
110110
----
@@ -170,7 +170,7 @@ Kotlin::
170170
----
171171
@PostMapping("/")
172172
fun handle(@Valid @RequestPart("meta-data") metadata: Mono<MetaData>): String {
173-
// ...
173+
// use one of the onError* operators...
174174
}
175175
----
176176
======

framework-docs/src/main/java/org/springframework/docs/web/webflux/controller/annmethods/partevent/PartEventController.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,28 @@ public class PartEventController {
3131

3232
// tag::snippet[]
3333
@PostMapping("/")
34-
public void handle(@RequestBody Flux<PartEvent> allPartsEvents) { // Using @RequestBody.
34+
public void handle(@RequestBody Flux<PartEvent> allPartEvents) {
3535

3636
// The final PartEvent for a particular part will have isLast() set to true, and can be
3737
// followed by additional events belonging to subsequent parts.
3838
// This makes the isLast property suitable as a predicate for the Flux::windowUntil operator, to
3939
// split events from all parts into windows that each belong to a single part.
40-
allPartsEvents.windowUntil(PartEvent::isLast)
41-
40+
allPartEvents.windowUntil(PartEvent::isLast)
4241
// The Flux::switchOnFirst operator allows you to see whether you are handling
43-
// a form field or file upload.
42+
// a form field or file upload
4443
.concatMap(p -> p.switchOnFirst((signal, partEvents) -> {
4544
if (signal.hasValue()) {
4645
PartEvent event = signal.get();
4746
if (event instanceof FormPartEvent formEvent) {
4847
String value = formEvent.value();
49-
// Handling the form field.
48+
// Handling the form field
5049
}
5150
else if (event instanceof FilePartEvent fileEvent) {
5251
String filename = fileEvent.filename();
5352

54-
// The body contents must be completely consumed, relayed, or released to avoid memory leaks.
53+
// The body contents must be completely consumed, relayed, or released to avoid memory leaks
5554
Flux<DataBuffer> contents = partEvents.map(PartEvent::content);
56-
// Handling the file upload.
55+
// Handling the file upload
5756
}
5857
else {
5958
return Mono.error(new RuntimeException("Unexpected event: " + event));

framework-docs/src/main/kotlin/org/springframework/docs/web/webflux/controller/annmethods/partevent/PartEventController.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,29 @@ class PartEventController {
3131

3232
// tag::snippet[]
3333
@PostMapping("/")
34-
fun handle(@RequestBody allPartsEvents: Flux<PartEvent>) { // Using @RequestBody.
34+
fun handle(@RequestBody allPartEvents: Flux<PartEvent>) {
3535

3636
// The final PartEvent for a particular part will have isLast() set to true, and can be
3737
// followed by additional events belonging to subsequent parts.
3838
// This makes the isLast property suitable as a predicate for the Flux::windowUntil operator, to
3939
// split events from all parts into windows that each belong to a single part.
40-
allPartsEvents.windowUntil(PartEvent::isLast)
40+
allPartEvents.windowUntil(PartEvent::isLast)
4141
.concatMap {
4242

4343
// The Flux::switchOnFirst operator allows you to see whether you are handling
44-
// a form field or file upload.
44+
// a form field or file upload
4545
it.switchOnFirst { signal, partEvents ->
4646
if (signal.hasValue()) {
4747
val event = signal.get()
4848
if (event is FormPartEvent) {
4949
val value: String = event.value()
50-
// Handling the form field.
50+
// Handling the form field
5151
} else if (event is FilePartEvent) {
5252
val filename: String = event.filename()
5353

54-
// The body contents must be completely consumed, relayed, or released to avoid memory leaks.
54+
// The body contents must be completely consumed, relayed, or released to avoid memory leaks
5555
val contents: Flux<DataBuffer> = partEvents.map(PartEvent::content)
56-
// Handling the file upload.
56+
// Handling the file upload
5757
} else {
5858
return@switchOnFirst Mono.error(RuntimeException("Unexpected event: $event"))
5959
}

0 commit comments

Comments
 (0)