我有一个3步骤来上传服务器上的文件:
以下是步骤2中从UI端获取文件的方法(EXT.JS):
@RequestMapping("/customerUploadFile/upload")
@ResponseBody
public JsonResponse uploadFile(CustomerUploadBean bean,
@RequestParam("filePath") MultipartFile filePath) throws IOException {
long fileSize = filePath.getSize();
HttpEntity<CustomerUploadBean> httpEntity = getHttpEntity(bean);
byte[] byteArr = filePath.getBytes();
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
parameters.add("userId", httpEntity.getHeaders().get("userId"));
parameters.add("file", byteArr);
// to set content type of header
org.springframework.http.HttpHeaders headers = new org.springframework.http.HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<JsonResponse> jsonResponse = restTemplate.exchange(uri, HttpMethod.POST,
new HttpEntity<MultiValueMap<String, Object>>(parameters, headers),
new ParameterizedTypeReference<JsonResponse>() {
});
JsonResponse response = jsonResponse.getBody();
if (jsonResponse.getStatusCode() == HttpStatus.OK) {
response.setSuccess(true);
} else {
response.setSuccess(false);
}
return response;
}
我已经验证过,filePath对象包含该文件并包含有关该文件的信息。
在步骤3,这是服务器上控制器中等待文件处理它的方法:
public Response importUserProfileCSV(
@ApiParam(value = "Service Name", required = true) @PathParam("service") String service,
@ApiParam(value = "CSV file to upload.", required = true) @FormDataParam("file") InputStream uploadedInputStream,
@ApiParam(value = "CSV file detail", required = true) @FormDataParam("file") FormDataContentDisposition fileDetail) {
return delegate.importUserProfileCSV(uploadedInputStream, fileDetail,
service, "user");
}
这里的问题是,在步骤3,在上面的方法中, fileDetail 对象只包含空值...我怎样才能调整方法步骤2(弹簧框架)到步骤3(球衣)的方法。