@RequestMapping(value = "{fileName:.+}", method = RequestMethod.POST, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<ResponseEnvelope<String>> uploadFile(
@RequestParam("ownerId") Long ownerId,
@PathVariable("fileName") String fileName,
@RequestBody MultipartFile file)
throws Exception {
ResponseEnvelope<String> env;
if(null == certFileContent) {
env = new ResponseEnvelope<String>("fail");
return new ResponseEntity<ResponseEnvelope<String>>(env, HttpStatus.OK);
}
service.uploadCertificate(ownerId, fileName, certFileContent.getBytes());
env = new ResponseEnvelope<String>("success");
return new ResponseEntity<ResponseEnvelope<String>>(env, HttpStatus.OK);
}
我经常遇到文件值为空的问题,但是我已经配置了multipart支持,请看下面的内容:
<form />
标签上添加了enctype="multipart/form-data"
(参见http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2)? - sp00m