users@jersey.java.net

[Jersey] Re: attaching file in jersey

From: <sree_at_work_at_yahoo.com>
Date: Thu, 20 Jan 2011 22:49:37 +0000 (GMT)

Hi,

I am able to do it using Apache HttpComponents.
Here is the code:

HttpPost httpPost = new HttpPost(RESTful URL);
httpPost.addHeader("Content-Type", "text/csv");

FileEntity fileEntity = new FileEntity(new File(fileName), "text/csv");
httpPost.setEntity(fileEntity);

HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(httpPost);

httpResponse.getStatusLine();

JSONObject json = new JSONObject(EntityUtils.toString(httpEntity));

I can switch back to Jersey in my project,
provided the above scenario can be made working using Jersey.

Looking forward for your help.

Thanking you,

With Regards
Sree