S
S
springboot7772022-01-25 12:01:21
Java
springboot777, 2022-01-25 12:01:21

Why Bad Request, status=400 when uploading files?


Whitelabel Error Page This
application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Jan 25 13:54:17 YEKT 2022
There was an unexpected error (type=Bad Request, status=400).

Controller

@GetMapping("/uploadtest")
    public String uploadtest(Model model) {
         return "upload";
    }
    
    @PostMapping("/postupload")
    public String postupload(@RequestParam("files") MultipartFile[] images,Model model) {
         return "upload";
    }

The form
<form method="post" action="/postupload" enctype="multipart/form-data">
          <input type="file" name="images" multiple class="form-control" accept=".jpg, .jpeg" >
         <button type="submit" >Upload</button>

    </form>


if you remove @RequestParam("files") MultipartFile[] images then it works
Why the error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2022-01-25
@springboot777

Good afternoon!
Your input is calledimages

<input type="file" name="images" multiple class="form-control" accept=".jpg, .jpeg" >

In the controller you expectfiles
@RequestParam("files") MultipartFile[] images

S
springboot777, 2022-01-25
@springboot777

@RequestParam("files") MultipartFile[] files
solved the problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question