控制器:
@RequestMapping(value = "/media", method = RequestMethod.POST, produces = "application/json", consumes = "multipart/form-data")
@ResponseBody
public MediaDto addMedia(@RequestParam(name = "file") MultipartFile file) throws IOException {
LOG.info("Adding media file with name={}", file.getOriginalFilename());
配置
@Bean
public MultipartResolver multipartResolver() {
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
commonsMultipartResolver.setMaxUploadSize(90000000);
commonsMultipartResolver.setDefaultEncoding("UTF-8");
return commonsMultipartResolver;
}
Angular
<input onchange="angular.element(this).scope().uploadFile(this)" id="chooseFile" name="file" type="file"
1条答案
按热度按时间daolsyd01#
输入标记中的id应该与控制器中的@RequestParam(name=“file”)name参数命名相同