users@jersey.java.net

[Jersey] attaching file in jersey

From: <sree_at_work_at_yahoo.com>
Date: Tue, 18 Jan 2011 22:36:34 +0000 (GMT)

Hi All,

Does anyone have a sample jersey client for the equivalent
"cURL -T fileName.csv -H Content-Type:text/csv
http://localhost:8080/handleCSVs"

So far I tried, that didn't work:
1.
MultiPart multiPart = new MultiPart();
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart(nameOfFile,
new File(nameOfFile));
multiPart.bodyPart(fileDataBodyPart);

ClientResponse response =
                webResource
                                .type("text/csv")
                                .post(ClientResponse.class, multiPart);
                
System.out.println("Status:" + response.getClientResponseStatus());

2.
String content = ... // read entire file into a String
ClientResponse cfResponse =
                webResource
                                .type(MediaType.TEXT_PLAIN_TYPE)
                                .post(ClientResponse.class, content);

System.out.println("Status:" + response.getClientResponseStatus());

Thanks, in advance.

Sree