5
@Controller public class UploadController { @PostMapping("/upload") public String upload(@RequestParam("file") MultipartFile file) { // save } } 

How to specify/config that only images(jpeg, png) are allowed to be uploaded?

1 Answer 1

1

You should do a check on file.getContentType() if it matches "image/jpeg" or "image/png". Not sure if consumes property of the @PostMapping would work because the request is of type "multipart/form-data" or "application/x-www-form-urlencoded" it seems.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.