Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I faced the same issue. It got solved by changing maven dependency for jersey-multipart jar from 1.0.2 to 1.8 version (Used the same dependency in client side as well as provider side.</p> <pre><code> &lt;dependency&gt; &lt;groupId&gt;com.sun.jersey.contribs&lt;/groupId&gt; &lt;artifactId&gt;jersey-multipart&lt;/artifactId&gt; &lt;version&gt;1.8&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>Here's the complete piece of code I'm using</p> <pre><code>File file = new File("E:/Goodies/tmp/sparrow.jpg"); byte[] logo = FileUtils.readFileToByteArray(file); MultiPart multiPart = new MultiPart().bodyPart(new BodyPart(logo, MediaType.APPLICATION_OCTET_STREAM_TYPE)); // POST the request try{ ClientResponse response = service.type("multipart/mixed").post(ClientResponse.class, multiPart); System.out.println("Response Status : " + response.getEntity(String.class)); }catch(Exception e){ e.printStackTrace(); } </code></pre> <p>and in the webservice:</p> <pre><code>@POST @Consumes("multipart/mixed") @Path("/upload") public Response post(MultiPart multiPart) { BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(0) .getEntity(); boolean isProcessed = false; String message = null; try { InputStream source = bpe.getInputStream(); BufferedImage bi = ImageIO.read(source); File file = new File("E:/Goodies/tmp" + "123.jpg"); // storing the image to file system. if (file.isDirectory()) { ImageIO.write(bi, "jpg", file); } else { file.mkdirs(); ImageIO.write(bi, "jpg", file); } isProcessed = true; } catch (Exception e) { message = e.getMessage(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload