我需要从vaadin向REST服务发送一个Multipart文件数据。我怎样才能实现它? ..(Web服务API列在下面)
@RequestMapping(value="/upload", method=RequestMethod.POST)
public @ResponseBody String[] handleFileUpload(
@RequestParam( value="file" , required=false) MultipartFile file , @RequestParam( value="title" , required=false)String title ,@RequestParam( value="description" , required=false)String description ){
// file uploading logic....
}
答案 0 :(得分:1)
在Java / VAADIN中使用基于外部HTTP的服务时,我特别使用非常好的JODD Java库http://jodd.org/doc/http.html
要按照相关说明将附件发布到网址,只需使用以下内容:
HttpRequest httpRequest = HttpRequest
.post("http://server:8080/upload")
.form(
"file", new File("c:\\a.jpg.zip")
);
HttpResponse httpResponse = httpRequest.send();
HttpRequest是来自JODD库的对象。您可以将JODD包含到maven配置中,例如http://jodd.org/download/