naXa stands with Ukraine
naXa stands with Ukraine

Reputation: 37993

Spring MVC - POST a list of files with max count limit

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@PostMapping(value = "/upload",
        consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public @ResponseBody ResponseBody uploadAttachments(
        @RequestParam(value = "comment", required = true) String comment,
        @RequestPart(value = "files", required = false) List<MultipartFile> files
) {
    /* do magic */
}

I'm using this mapping to process a form with attachments. It consumes multipart/form-data.

How can I limit the maximum number of attached files to 10?

Upvotes: 0

Views: 2922

Answers (1)

masadwin
masadwin

Reputation: 462

as indicated in this answer Spring Web MVC - validate individual request params

use @Size(max = ?) annotation on your parameter to limit the input size

Upvotes: 2

Related Questions