{"id":5471,"date":"2014-03-30T22:24:55","date_gmt":"2014-03-30T22:24:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/jersey-file-upload-collection-of-common-programming-errors\/"},"modified":"2014-03-30T22:24:55","modified_gmt":"2014-03-30T22:24:55","slug":"jersey-file-upload-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/jersey-file-upload-collection-of-common-programming-errors\/","title":{"rendered":"Jersey File Upload-Collection of common programming errors"},"content":{"rendered":"<p>I tried to upload a file to my jersey server, but there is an error.<\/p>\n<pre><code> Writer output = null;\n    File file = null;\n    try {\n      String text = \"Rajesh Kumar\";\n      file = new File(\"write.txt\");\n      output = new BufferedWriter(new FileWriter(file));\n        output.write(text);\n        output.close();\n    } catch (IOException e) {\n        e.printStackTrace();\n    }\n\n    InputStream is = null;\n\n    try {\n        is = new FileInputStream(file);\n        is.close(); \n    } catch (FileNotFoundException e) {\n        e.printStackTrace();\n    } catch (IOException e) {\n        e.printStackTrace();\n    }\n\n    FormDataMultiPart part = new FormDataMultiPart().field(\"file\", is, MediaType.TEXT_PLAIN_TYPE);\n    System.out.println(is);\n    System.out.println(tenant1.getTenantId());\n    System.out.println(part);\n    String response = service.path(\"rest\").path(\"file\").type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, part);\n<\/code><\/pre>\n<p>The Syso are not null. So the File was written to the inputstream.<\/p>\n<p>Error:<\/p>\n<pre><code>ClientHandlerException: java.io.IOException: ReadError , when I send it to the server.\n<\/code><\/pre>\n<p>Server Side:<\/p>\n<pre><code>@POST\n@Path(\"\/file\")\n@Consumes(MediaType.MULTIPART_FORM_DATA)\npublic Response postFileTenant(@FormDataParam(\"file\") InputStream stream) throws IOException {\n\n    \/\/ save it\n\n    return Response.ok(IOUtils.toString(stream)).build();\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I tried to upload a file to my jersey server, but there is an error. Writer output = null; File file = null; try { String text = &#8220;Rajesh Kumar&#8221;; file = new File(&#8220;write.txt&#8221;); output = new BufferedWriter(new FileWriter(file)); output.write(text); output.close(); } catch (IOException e) { e.printStackTrace(); } InputStream is = null; try { is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5471","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5471"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5471\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}