service code:
@RequestMapping(value="/uploadFile", method=RequestMethod.POST, consumes = "multipart/form-data")
public String uploadFile(@RequestParam("file") MultipartFile file,@RequestParam("filePath") String filePath){
//logic here
}
Part of the client code:
public static synchronized String responseOfPost(String restUrl, FileSystemResource file,String filePath) {
PostMethod post = new PostMethod(restUrl);
HttpClient client = new HttpClient();
post.setParameter("filePath", filePath);
try {
Part[] parts = {new FilePart("file",file.getFile())};
post.addRequestHeader("Content-Type", "multipart/form-data; boundary=Endedlogging");
if (file != null) {
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
}
client.executeMethod(post);
String response = post.getResponseBodyAsString();
} catch (final IOException e) {
e.printStackTrace();
}
return null;
}
this is the error I am getting:
org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'file' is not present
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:251)
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:96)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
How can I pass multipart file("file") and filePath("filePath") to POST method in client code? NOT FROM UI