Multipart has a special format. If the server expects multipart / form-data format, we cannot just send it as a regular request. You can see the preview window in Postman to see the format


You can see that each part has a border. We do not need to worry about installing this manually. Resteasy has an API for building multiform output. You can use the MultipartFormDataOutput class to build the output. Just use the addFormData method to add details. In your case, this is only one part, but the request will still be formatted as the server expects.
So your query should look something like
MultipartFormDataOutput output = new MultipartFormDataOutput();
It is assumed that you have the required dependency as I get the image if the server accepts multipart
<dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-multipart-provider</artifactId> <version>${resteasy.version}</version> </dependency>
And just for completeness ...
For future readers interested in the server side (since you did not provide your code), this is what I used for testing
@Path("/multipart") public class MultipartResource { @POST @Consumes(MediaType.MULTIPART_FORM_DATA) public Response postData(MultipartFormDataInput input) throws Exception { byte[] bytes = input.getFormDataPart("file", byte[].class, null); JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bytes))); return Response.ok("GOT IT").build(); } }
Paul Samsotha Dec 23 '14 at 15:17 2014-12-23 15:17
source share