Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is bug in Jersey. See <a href="http://jersey.576304.n2.nabble.com/Chunked-encoding-problem-td4742270.html" rel="nofollow">Chunked encoding problem</a>.</p> <p>This problem appears only for few clients (iOS, Android).</p> <p>If you set the Content-Type to application/octet-stream, then the Jersey MessageWriter for the application/octet-stream will set the Content-Length and not send as chunked transport method. </p> <p>There is <a href="http://davidbuccola.blogspot.com/2009/09/configure-jersey-chunked-encoding-when.html" rel="nofollow">solution</a> for Jersey Client:</p> <pre><code>ClientConfig config = new DefaultClientConfig(); config.getProperties().put(ClientConfig.PROPERTY_CHUNKED_ENCODING_SIZE, 32 * 1024); </code></pre> <p>But it doesn't work for the <strong>iOS's or Android's client</strong>. So I tested Apache File Upload. Threre was another bug: "Stream ended unexpectedly".</p> <p>Only <strong><a href="http://www.servlets.com/cos/" rel="nofollow">Oreilly upload</a></strong> can upload file correct for all clients. This is my code:</p> <pre><code>public Object[] getParametersAndFiles(HttpServletRequest request) throws IOException { log.debug("OreillyUpload"); Properties params = new Properties(); LinkedHashMap files = new LinkedHashMap(); File tempDirectory = new File(System.getProperty("java.io.tmpdir")); MultipartParser mp = new MultipartParser(request, 1*1024*1024); // 10MB Part part; while ((part = mp.readNextPart()) != null) { String name = part.getName(); if (part.isParam()) { // it's a parameter part ParamPart paramPart = (ParamPart) part; String value = paramPart.getStringValue(); params.put(name, value); log.debug("param; name=" + name + ", value=" + value); } else if (part.isFile()) { // it's a file part FilePart filePart = (FilePart) part; String fileName = filePart.getFileName(); if (fileName != null) { // the part actually contained a file File file = new File(tempDirectory,fileName); long size = filePart.writeTo(file); files.put(name, file); log.debug("file; name=" + name + "; filename=" + fileName + ", filePath=" + filePart.getFilePath() + ", content type=" + filePart.getContentType() + ", size=" + size); } else { // the field did not contain a file log.debug("file; name=" + name + "; EMPTY"); } } } return new Object[] {params, files}; } </code></pre> <p>And this is Jersey Server code (warning all Jersey Upload anotations (like as "@FormDataParam") should be removed):</p> <pre><code>@POST @Path("uploadMarkup") @Produces(MediaType.APPLICATION_JSON) // @Consumes(MediaType.MULTIPART_FORM_DATA) //// public void uploadMarkup( // public JSONWithPadding uploadMarkup( // @FormDataParam("markupFile") InputStream markupFile, // @FormDataParam("markupFile") FormDataContentDisposition details, // @FormDataParam("slideNum") int slideNum) { public JSONWithPadding uploadMarkup(@Context HttpServletRequest request) { Object[] data = uploadService.getParametersAndFiles(request); ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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