chathura
chathura

Reputation: 31

Invoke A Multipart REST Service with vaadin

I need to send a Multipart file data to REST service from vaadin . How can I achieve it ? .. ( web service API is listed below)

 @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....

}

Upvotes: 0

Views: 493

Answers (1)

David Marko
David Marko

Reputation: 2519

When working with external HTTP based services in Java / VAADIN I'm ussualy using very nice JODD Java library specificaly http://jodd.org/doc/http.html

To post attachment to URL as explained in question, simply use something like this:

HttpRequest httpRequest = HttpRequest
        .post("http://server:8080/upload")
        .form(
            "file", new File("c:\\a.jpg.zip")
        );

    HttpResponse httpResponse = httpRequest.send();

HttpRequest is object from JODD library. You can include JODD into maven config e.g. http://jodd.org/download/

Upvotes: 1

Related Questions