HttpMediaTypeNotSupportedException: Content type 'video/mp4' not supported. While uploading video reavtive Spring webflux via Postman

Viewed 281

I want to upload a video using the reactive paradigm. I am trying to create a Controller which will take Mono as @RequestPart and store it into MongoDb via reactive stream (Spring webflux).

My controller looks like this:

@PostMapping(value = "/add/react", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Mono<ResponseEntity> upload(@RequestPart(name = "file") Mono<FilePart>fileParts) throws Exception {
    return fileParts
            .flatMap(part -> this.gridFsTemplate.store(part.content(), part.filename()))
            .map((id) -> ok().body(Map.of("id", id.toHexString())));
}

I am trying to add a Multipart file via Postman: enter image description here

But in the end, I am receiving this message

2021-02-23 16:38:26.498  WARN 23456 --- [nio-8088-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'video/mp4' not supported]

Could you help me, please? I have searched google for 2 days and did not find anything.

1 Answers

The problem with the code that I have used Tomcat. But Tomcat cannot convert multipart file into Flux/Mono The solution to my problem is to change the webserver. Instead of Tomcat, I am using Netty now. And all works fine

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-reactor-netty</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
Related