Java 类org.springframework.http.codec.multipart.Part 实例源码

项目:httpstub    文件:RequestResponseLogger.java   
public void logRequest(ServerRequest request, MultiValueMap<String, ?> map) {
    if (configHolder.getConfig().getLogging().isHeaders()) {
        logRequestHeaders(request);
    }
    if (configHolder.getConfig().getLogging().isBody()) {
        map.forEach((key, values) -> values.forEach(value -> {
            if (value instanceof Part) {
                val part = (Part) value;
                part.headers().forEach((headerKey, headerValues) -> headerValues.forEach(headerValue ->
                    log.info("{} [{}] {}: {}", RECEIVED, key, headerKey, headerValue)));
            } else {
                log.info("{} {}={}", RECEIVED, key, value);
            }
        }));
    }
}
项目:spring-reactive-sample    文件:MultipartController.java   
@PostMapping(value = "", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Mono<String> requestBodyFlux(@RequestBody Flux<Part> parts) {
    return partFluxDescription(parts);
}
项目:spring-cloud-gateway    文件:BaseWebClientTests.java   
@RequestMapping(value = "/post", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<Map<String, Object>> postFormData(@RequestBody Mono<MultiValueMap<String, Part>> parts) {
    // StringDecoder decoder = StringDecoder.allMimeTypes(true);
    return parts.flux().flatMap(map -> Flux.fromIterable(map.values()))
            .flatMap(map -> Flux.fromIterable(map))
            .filter(part -> part instanceof FilePart)
            .reduce(new HashMap<String, Object>(), (files, part) -> {
                MediaType contentType = part.headers().getContentType();
                long contentLength = part.headers().getContentLength();
                files.put(part.name(), "data:"+contentType+";base64,"+contentLength); //TODO: get part data
                return files;
            }).map(files -> Collections.singletonMap("files", files));
}
项目:spring-reactive-sample    文件:MultipartController.java   
private static String partMapDescription(MultiValueMap<String, Part> partsMap) {
    return partsMap.keySet().stream().sorted()
        .map(key -> partListDescription(partsMap.get(key)))
        .collect(Collectors.joining(",", "Map[", "]"));
}
项目:spring-reactive-sample    文件:MultipartController.java   
private static Mono<String> partFluxDescription(Flux<? extends Part> partsFlux) {
    return partsFlux.log().collectList().map(MultipartController::partListDescription);
}
项目:spring-reactive-sample    文件:MultipartController.java   
private static String partListDescription(List<? extends Part> parts) {
    return parts.stream().map(MultipartController::partDescription)
        .collect(Collectors.joining(",", "[", "]"));
}
项目:spring-reactive-sample    文件:MultipartController.java   
private static String partDescription(Part part) {
    return part instanceof FilePart ? part.name() + ":" + ((FilePart) part).filename() : part.name();
}