{"action":"created","issue":{"url":"https://api.github.com/repos/netty/netty/issues/3303","labels_url":"https://api.github.com/repos/netty/netty/issues/3303/labels{/name}","comments_url":"https://api.github.com/repos/netty/netty/issues/3303/comments","events_url":"https://api.github.com/repos/netty/netty/issues/3303/events","html_url":"https://github.com/netty/netty/issues/3303","id":53368780,"number":3303,"title":"uploadFile error 4.0.15","user":{"login":"timershu","id":8155279,"avatar_url":"https://avatars.githubusercontent.com/u/8155279?v=3","gravatar_id":"","url":"https://api.github.com/users/timershu","html_url":"https://github.com/timershu","followers_url":"https://api.github.com/users/timershu/followers","following_url":"https://api.github.com/users/timershu/following{/other_user}","gists_url":"https://api.github.com/users/timershu/gists{/gist_id}","starred_url":"https://api.github.com/users/timershu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timershu/subscriptions","organizations_url":"https://api.github.com/users/timershu/orgs","repos_url":"https://api.github.com/users/timershu/repos","events_url":"https://api.github.com/users/timershu/events{/privacy}","received_events_url":"https://api.github.com/users/timershu/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/netty/netty/labels/defect","name":"defect","color":"e11d21"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/netty/netty/milestones/109","labels_url":"https://api.github.com/repos/netty/netty/milestones/109/labels","id":918308,"number":109,"title":"4.0.26.Final","description":null,"creator":{"login":"trustin","id":173918,"avatar_url":"https://avatars.githubusercontent.com/u/173918?v=3","gravatar_id":"","url":"https://api.github.com/users/trustin","html_url":"https://github.com/trustin","followers_url":"https://api.github.com/users/trustin/followers","following_url":"https://api.github.com/users/trustin/following{/other_user}","gists_url":"https://api.github.com/users/trustin/gists{/gist_id}","starred_url":"https://api.github.com/users/trustin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trustin/subscriptions","organizations_url":"https://api.github.com/users/trustin/orgs","repos_url":"https://api.github.com/users/trustin/repos","events_url":"https://api.github.com/users/trustin/events{/privacy}","received_events_url":"https://api.github.com/users/trustin/received_events","type":"User","site_admin":false},"open_issues":52,"closed_issues":4,"state":"open","created_at":"2014-12-31T07:43:52Z","updated_at":"2015-01-07T05:15:40Z","due_on":null,"closed_at":null},"comments":16,"created_at":"2015-01-05T06:39:04Z","updated_at":"2015-01-08T08:26:14Z","closed_at":"2015-01-05T06:50:51Z","body":"Some file upload will be in error, some not\r\n![netty-file](https://cloud.githubusercontent.com/assets/8155279/5609977/67d41d5c-94e8-11e4-982a-5ad697c82323.png)\r\n\r\npublic static boolean uploadFile(Bootstrap b,final File file,String host,int port) throws Exception {\r\n    \tHttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE);\r\n        if (!file.canRead()) {\r\n            throw new FileNotFoundException(file.getAbsolutePath()+\"/\"+file.getName());\r\n        }\r\n        URI uriFile = new URI(\"/formpost/zhenai\" );\r\n        // Start the connection attempt.\r\n        final ChannelFuture cf = b.connect(new InetSocketAddress(host, port));\r\n        // Connection established successfully\r\n        // Wait until the connection attempt succeeds or fails.\r\n        Channel channel = cf.sync().channel();\r\n\r\n        System.out.println(\"uriFile.toASCIIString()==\"+uriFile.toASCIIString());\r\n        // Prepare the HTTP request.\r\n        HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uriFile.toASCIIString());\r\n\r\n        // Use the PostBody encoder\r\n        HttpPostRequestEncoder bodyRequestEncoder =\r\n                new HttpPostRequestEncoder(factory, request, true); // true => multipart\r\n\r\n      \r\n        // add Form attribute\r\n        bodyRequestEncoder.addBodyFileUpload(\"file\", file, \"application/x-zip-compressed\", false);\r\n        // finalize request\r\n        try {\r\n            request = bodyRequestEncoder.finalizeRequest();\r\n        } catch (Exception e) {\r\n            e.printStackTrace();\r\n            return false;\r\n        }\r\n        // send request\r\n        channel.write(request);\r\n        // test if request was chunked and if so, finish the write\r\n        if (bodyRequestEncoder.isChunked()) {\r\n        \tChannelFuture cFuture=channel.writeAndFlush(bodyRequestEncoder);\r\n        } else {\r\n            channel.flush();\r\n        }\r\n        // Now no more use of file representation (and list of HttpData)\r\n        bodyRequestEncoder.cleanFiles();\r\n        // Wait for the server to close the connection.\r\n        channel.closeFuture().sync();\r\n        //callback.call(true);\r\n        return true;\r\n    }\r\n"},"comment":{"url":"https://api.github.com/repos/netty/netty/issues/comments/69149322","html_url":"https://github.com/netty/netty/issues/3303#issuecomment-69149322","issue_url":"https://api.github.com/repos/netty/netty/issues/3303","id":69149322,"user":{"login":"timershu","id":8155279,"avatar_url":"https://avatars.githubusercontent.com/u/8155279?v=3","gravatar_id":"","url":"https://api.github.com/users/timershu","html_url":"https://github.com/timershu","followers_url":"https://api.github.com/users/timershu/followers","following_url":"https://api.github.com/users/timershu/following{/other_user}","gists_url":"https://api.github.com/users/timershu/gists{/gist_id}","starred_url":"https://api.github.com/users/timershu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timershu/subscriptions","organizations_url":"https://api.github.com/users/timershu/orgs","repos_url":"https://api.github.com/users/timershu/repos","events_url":"https://api.github.com/users/timershu/events{/privacy}","received_events_url":"https://api.github.com/users/timershu/received_events","type":"User","site_admin":false},"created_at":"2015-01-08T08:26:14Z","updated_at":"2015-01-08T08:26:14Z","body":"![netty05](https://cloud.githubusercontent.com/assets/8155279/5659773/0e6d67f6-9753-11e4-9235-cc2a6c87d5c0.png)\r\n"}}