0
votes

The request params are shown in the network but the second param (fileId) is received as null in the controller. The request returns 400 bad request.

@PostMapping(path = "/uploadFile")
public ResponseEntity<ServiceResponse> upload(
        @RequestParam(value = "id") Long userId,
        @RequestParam(value = "fileId") Long fileId,
        @RequestPart(value = "file") MultipartFile... file) {

    // 
        return ResponseEntity.ok(serviceResponse);
}

request URL: (the file is sent in the body: formData) http://localhost:8080/api/upload?id=9999&fileId=101

2
Do you also send a fileId key in your form-data? i.e. does the file parameter contain a fileId key? Because your fileId RequestParam should not be null with the request you provided, unless a fileId key is also part of the MultipartFile. - Troley
@Chaimae Aklibous There are a couple or reasons that could happen in Spring-MVC your controller has to have fileID in Model class to know it can be used. - April_Nara

2 Answers

0
votes

Well, could you show your request or the URL atleast?

0
votes

Your URL should be http://localhost:8080/api/uploadFile?id=9999&fileId=101 instead of http://localhost:8080/api/upload?id=9999&fileId=101 because you have mentioned path as uploadFile