0

I am using postman to make a call to an api that is accepting 4 form parameter as input and one of the parameter is of type file. I am successfully able to make a call using postman. When I am trying the same call from code using JAX-RS 2.0 Client API, I am not able to figure out how to send this. Please help with this. I have to use JAX-RS only as per the framework.

  WebTarget  target = client.target(BASE_URL); 
  Invocation.Builder invocationBuilder = target.request();
  File file = new File("/Users/akash/file.jks");
//InputStream inputFileStream = new FileInputStream(file);
  Form formInput = new Form();
  formInput.param("alias", "client alias");
  formInput.param("keypasswd", "***");
  formInput.param("storepasswd", "***");
//formInput.param("jkskeystore",inputFileStream );
Akash Kumar
  • 165
  • 1
  • 12
  • 1
    Check this answer https://stackoverflow.com/questions/27609569/file-upload-along-with-other-object-in-jersey-restful-web-service – GSSwain Dec 13 '18 at 04:04
  • Are you using the [form-data] button in Postman? If so, you need to use multipart data type. The link above has an example of how to do it with the Jersey client. – Paul Samsotha Dec 13 '18 at 04:16
  • 1
    Here is the [documentation](https://jersey.github.io/documentation/latest/media.html#d0e8965). You also need to add the jersey-media-multipart dependency to your project. – Paul Samsotha Dec 13 '18 at 04:18
  • Thanks @PaulSamsotha ! It worked. your documentation url really helped. – Akash Kumar Dec 13 '18 at 06:32

0 Answers0