0

I am using apache HTTP Client for callin rest endpoints.

I want to call a POST request with image and some more form data as parameters. I can do them separately with to requests like first for the form data and the other for the image alone.

Is there any possible solution so that i can do it with one request.

Below is the api call

http://<url>?hint=hi&def=ready&image=<imagefile>
rozar
  • 1,058
  • 3
  • 15
  • 28

1 Answers1

1

Use Multipart Request. Commons Apache File Upload API has very good API for the same. Apache Commons HttpClient has the API for client also.

Else, use Servlet 3.0 container which has support for multipart data. Where the String part type will be provided with HttpServletRequest.getParameter() method. And the File type parts can be retrieved using HttpServletRequest.getPart() method.

Ramesh PVK
  • 15,200
  • 2
  • 46
  • 50
  • Thanks Ramesh.. I am actually using what you pointed. But I dont know how to make a request with both UrlEncodedFormEntity and MultipartEntity as defined in the Commons Apache. Bascially, i need a single POST request with both MultipartEntity for image and UrlEncodedFormEntity for the form details. – rozar May 30 '12 at 06:51
  • I am saying dont use both, send those url paramters like multipart form date. Which can have images and sting which are nothing but Parameters. – Ramesh PVK May 30 '12 at 07:14
  • Updated my answer. can please check. – Ramesh PVK May 30 '12 at 07:17
  • Thanks Ramesh. But I used FileItemFactory and completed :-) – rozar Jun 22 '12 at 05:38