users@jersey.java.net

[Jersey] Re: attaching file in jersey

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Wed, 19 Jan 2011 10:27:59 +0100

Hi,

text/csv is not the media type for multipart messages so you need to
change the media type in 1) to multipart/mixed.

Without any more information on what the server side is i cannot
really help you much.

Paul.

On Jan 18, 2011, at 11:36 PM, sree_at_work_at_yahoo.com wrote:

> 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