Last active
February 24, 2018 22:41
-
-
Save entzik/05aa654789fc855d95f1ddcdfc257732 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping(path = "/api/files") | |
public class ReactiveUploadResource { | |
Logger LOGGER = LoggerFactory.getLogger(ReactiveUploadResource.class); | |
/** | |
* upload handler method, mapped to POST. Like any file upload handler it consumes MULTIPART_FORM_DATA. | |
* Produces a JSON respomse | |
* | |
* @param parts a flux providing all part contained in the MULTIPART_FORM_DATA request | |
* @return a flux of results - one element per uploaded file | |
*/ | |
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | |
public Flux<String> uploadHandler(@RequestBody Flux<Part> parts) { | |
return parts | |
.filter(part -> part instanceof FilePart) // only retain file parts | |
.ofType(FilePart.class) // convert the flux to FilePart | |
.flatMap(this::saveFile); // save each file and flatmap it to a flux of results | |
} | |
.... | |
private Mono<String> saveFile(FilePart filePart) { | |
.... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment