Thx for the quick and helpfull anwers!
I found a sollution @
http://evgenyg.wordpress.com/2010/05/01/uploading-files-multipart-post-apache/
though it is not via RestAssured
Here is the code that does the trick for me:
String url = "
http://localhost:8083/myapp/rest/template";
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
HttpPost post = new HttpPost( url );
MultipartEntity entity = new
MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
// For File parameters
File f = new File(PATH_TO_FILE);
entity.addPart( "pdf", new FileBody(( File ) f , "application/
pdf" ));
// For usual String parameters
entity.addPart( "name", new StringBody( "testTemplate", "text/
plain", Charset.forName( "UTF-8" )));
post.setEntity( entity );
// Here we go!
String response =
EntityUtils.toString( client.execute( post ).getEntity(), "UTF-8" );
System.out.println("============== RESPONSE
=======================");
System.out.println(response);
System.out.println("============== END_RESPONSE
=======================");
client.getConnectionManager().shutdown();
Regards,
Tim
> Interesting. I know people have got it to work with http builder by using a
> very ugly work-around<
http://groovy.329449.n5.nabble.com/HTTPBuilder-multipart-message-td34...>that
> I don't like but Rest Assured doesn't expose the necessary methods to
> make it work right now. If possible I'd like to find another easier solution
> like this:
>
> File file = ..
> given().body(myFile).when().post("..");
>
> This should automatically choose multipart upload. But I don't know how to
> implement this in a nice way under the hood. If we're lucky it may be as
> simple as you say that you only change the content-type to multipart but I'm
> not sure. Perhaps you could checkout the source and try to hard code content
> type and see if it works with the MultipartEntity?
>
> /Johan
>