SynchronossFormFieldPart cannot be cast to FilePart

Viewed 422

I'm new to Spring Webflux, and I've been struggling to find solution to my issue: I have a webclient, that receive a FilePart and needs to post it (upload the file) to another service:

fun upload(file: Mono<FilePart>): Mono<String> =
    webClient
        .post()
        .uri("/upload")
        .contentType(MediaType.MULTIPART_FORM_DATA)
        .accept(MediaType.TEXT_PLAIN)
        .body(
            BodyInserters.fromMultipartData(
                "file",
                file.flatMapMany(FilePart::content)
            )
        )
        .exchange()
        .flatMap { it.bodyToMono<String>() }

The service:

fun save(file: Mono<FilePart>): Mono<String> =
    file.map(::SomeClass)
        .flatMap {
            // some operations
        }

Where SomeClass Constructor:

class SomeClass(
    private val part: FilePart
)

In postman I was able to upload the file, but through my application I received:

java.lang.ClassCastException: class org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader$SynchronossFormFieldPt cannot be cast to class org.springframework.http.codec.multipart.FilePart

How do I resolve this?

Thanks!

0 Answers
Related