I am trying to upload an image using the Jersey web service, I am using a jersey client to upload the image. below is a jersey web service that accepts an input stream and uploads an image to a server. it works fine when i call it directly using jsp multipart form upload but fails when i upload images using jersey client
@POST @Path("/upload") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFile( @FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) throws ServiceException {
Below, the jersey client uploads the image, the client code is part of another web service that is called from the php rest client and this jersey client call to download the web service to download the image, if I directly call the jersey web service to download the image, it works fine but it doesnβt work when I load using the jersey client.
ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); client.setChunkedEncodingSize(1024); WebResource wr = client .resource("http://localhost:8080/rest/upload"); String contentDisposition = "attachment; filename=\"" + fileDetail.getName() + "\""; FormDataMultiPart form = new FormDataMultiPart(); ContentDisposition contentDisposition2 = new ContentDisposition(contentDisposition); form.setContentDisposition(contentDisposition2); FormDataBodyPart fdp = new FormDataBodyPart("file", uploadedInputStream, MediaType.MULTIPART_FORM_DATA_TYPE); form.bodyPart(fdp); ClientResponse response = wr.type(MediaType.MULTIPART_FORM_DATA).post( ClientResponse.class, form)
Please help me not to know what I do not see here. Thanks.
source share