Skip to content

Add support multipart request parts in RequestBean #11682

Open
@altro3

Description

@altro3

Feature description

Test request:
Image

Example controller on spring boot:

    @PostMapping(value = "/testMultipart/{pathVar}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public void testMultipart(WrappedRq rq) {
        log.info("fileName: {}", rq.fileName.getBytes());
    }

    public record WrappedRq(
        @PathVariable
        String pathVar,
        @RequestParam
        String queryVar,
        // Part from multipart body
        String fileName,
        // Part from multipart body
        MultipartFile file
    ) {}

Request debug:

Image

As you see, attributes String fileName and MultipartFile file filled correctly.

Example on micronaut:

    @Post(value = "/testMultipart/{pathVar}", consumes = MediaType.MULTIPART_FORM_DATA)
    public void testMultipart(@RequestBean WrappedRq rq) {
        log.info("fileName: {}", rq.fileName.getBytes());
    }

    @Introspected
    public record WrappedRq(
        @PathVariable
        String pathVar,
        @QueryValue
        String queryVar,
        // Part from multipart body
        String fileName,
        // Part from multipart body
        CompletedFileUpload file
    ) {
    }

Request debug:

Image

I see two problems that would be good to fix:

  1. At the moment, even if you specify the @Part annotations to the fileName and file attributes, Micronaut still won't understand what to put there. That is, at the moment it is impossible to use RequestBean and multipartfirmdata normally.

  2. Micronaut cannot correctly determine that the parameter of the endpoint method describes a @RequestBean unless you explicitly specify the annotation. Although this can be easily done if you analyze the WrappedRq class and see that the value is Consumes.

In addition, Spring Boot understands constructions with a list of multipart files and puts all the parsed files there

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions