Below is my Rest api which accepts a multipart file and a custom dto
@RequestMapping(path="/manual", method = RequestMethod.POST)
public ResponseEntity<?> createObject(@RequestPart CustomDTO dto, @RequestPart(name = "file", required = true) MultipartFile file) {
//Some code here
}
Following is a CustomDTO
public class CustomDTO implements Serializable {
// Few attributes and its respective getters and setter are there
}
Now on making a request it gives me an error as below
But if in rest api instead of CustomDTO
if I make the data type as String then it works properly and then using objectmapper I am able to convert it to CustomDTO
. But please help me out on how to directly accept it as CustomDTO
and not String.
Note: Am using Spring Boot
try below one.
@RequestMapping(value = "/manual", method = RequestMethod.POST)
public ResponseEntity<?> createObject( @Valid CustomDTO dto, @RequestParam("file") MultipartFile file ) {
//
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.