Skip to content

Improving Spring Boot support: Correctly interpret endpoints with multipart form data#2080

Merged
altro3 merged 1 commit intomicronaut-projects:6.16.xfrom
altro3:spring-boot-multipart
Apr 9, 2025
Merged

Improving Spring Boot support: Correctly interpret endpoints with multipart form data#2080
altro3 merged 1 commit intomicronaut-projects:6.16.xfrom
altro3:spring-boot-multipart

Conversation

@altro3
Copy link
Collaborator

@altro3 altro3 commented Apr 9, 2025

Added support endpoints like these:

    @Post(value = "/file", consumes = MediaType.MULTIPART_FORM_DATA)
    // Query value, because for Spring Boot need to set annotation `@RequestParam` and it's mapped to `@QueryValue`
    // `json` parameter must be ignored, because it is map fo all query parameters, and we can't interpret it correct
    public void endpoint(@QueryValue Map<String, CompletedFileUpload> files, @QueryValue @Parameter(in = QUERY) Map<String, String> json) {
    }
    
    @Post(value = "/file", consumes = MediaType.MULTIPART_FORM_DATA)
    public void endpoint2(@QueryValue Map<String, CompletedFileUpload> files) {
    }

    @Post(value = "/fileWithJson", consumes = MediaType.MULTIPART_FORM_DATA)
    // Query value, because for Spring Boot need to set annotation `@RequestParam` and it's mapped to `@QueryValue`
    // in this case json will be interpreted as a part of multipart request 
    public void endpoint2(@QueryValue Map<String, CompletedFileUpload> files, @QueryValue Map<String, String> json) {
    }

    @Post(value = "/fileArray", consumes = MediaType.MULTIPART_FORM_DATA)
    public void endpoint3(CompletedFileUpload[] files) {
    }

    @Post(value = "/fileList", consumes = MediaType.MULTIPART_FORM_DATA)
    public void endpoint4(List<CompletedFileUpload> files) {
    }

    @Post(value = "/fileMapOfList", consumes = MediaType.MULTIPART_FORM_DATA)
    public void endpoint5(Map<String, List<CompletedFileUpload>> files) {
    }

@altro3 altro3 force-pushed the spring-boot-multipart branch from cad7905 to 00795fa Compare April 9, 2025 09:38
@altro3 altro3 added the type: improvement A minor improvement to an existing feature label Apr 9, 2025
@altro3 altro3 requested review from graemerocher and sdelamo April 9, 2025 12:42
@sdelamo sdelamo changed the base branch from 6.15.x to 6.16.x April 9, 2025 14:54
@sdelamo
Copy link
Contributor

sdelamo commented Apr 9, 2025

@altro3 please, resolve the conflict and merge.

@altro3 altro3 force-pushed the spring-boot-multipart branch from 00795fa to 9ab6657 Compare April 9, 2025 19:39
@altro3 altro3 merged commit 10f46e8 into micronaut-projects:6.16.x Apr 9, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: improvement A minor improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants