users@jersey.java.net

[Jersey] File upload in FormDataMultiPart with invalid Chinese filename in MS Windows

From: Brendan cheng <ccp999_at_hotmail.com>
Date: Sat, 29 Sep 2012 01:34:06 +0000

Hi, I found a strange problem that for the same file loading code work very well in OSX but not in Windows. The chinese filename get corrupted in Windows but not in OSX. I'm using Jersey 1.9 and the server is running Node.js. Is it a Java problem or Jersey? here is my code: FormDataMultiPart form = new FormDataMultiPart(); form.bodyPart(new FileDataBodyPart("thumbnail", file)); System.out.println("******************** =" + file.getName()); System.out.println("form.getContentDisposition().getFileName() =" + form.getBodyParts().get(0).getContentDisposition() .getFileName()); String s = clientResource.path("uploadTagFile").path(tagid) .type(MediaType.MULTIPART_FORM_DATA_TYPE) .accept(MediaType.APPLICATION_JSON).post(String.class, form); try { JSONObject j = (JSONObject) new JSONArray(s).get(0); System.out.println("******************** =" + j.toString()); return j; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } and the log returned from OSX: Keep-Alive-Timer, called close() Keep-Alive-Timer, called closeInternal(true) Keep-Alive-Timer, SEND TLSv1 ALERT: warning, description = close_notify Keep-Alive-Timer, WRITE: TLSv1 Alert, length = 22 Keep-Alive-Timer, called closeSocket(selfInitiated) ******************** =人题啊.png form.getContentDisposition().getFileName() =人题啊.png Allow unsafe renegotiation: false Allow legacy hello messages: true ..... upload onSent: delta: 8192 bytes: 16589 WebUploadFile.this.totalBytes: 19813 upload onSent: delta: 3429 bytes: 20018 WebUploadFile.this.totalBytes: 19813 upload onSent: delta: 43 bytes: 20061 WebUploadFile.this.totalBytes: 19813 Sep 28, 2012 8:36:13 AM com.sun.jersey.api.client.filter.LoggingFilter log INFO: 1 * Client out-bound request 1 > POST https://192.168.56.101:8000/itags/uploadTagFile/10361 > Content-Type: multipart/form-data 1 > Accept: application/json --Boundary_1_1298626937_1348792573616 Content-Type: image/png Content-Disposition: form-data; filename="人题啊.png"; modification-date="Sat, 09 Jun 2012 14:30:06 GMT"; size=19813; name="thumbnail" ?PNG IHDRY'??L?iCCPICC Profilex?T?k?P??e???:g >h?ndStC??kW??Z?6?!H??m\??$?~?ًo:?w?>? كo{? ………. Jq ? ?? ?8@@Y.?R$ ? @??@@\ d??J? ? ?!?c@pA???*E"? ??,?@@?B? ?? ??8@@Y.?R$ ? @??@@\ d??J? ? ?!?c@pA???*E"? ??,?@@?B? ?? ??8@@Y.?R$ ? @??@@\ d??J? ? ?!?c@pA???*E"? ??,?@@?B? ?? ???NA???8IEND?B`? --Boundary_1_1298626937_1348792573616-- Thread-12, WRITE: TLSv1 Application Data, length = 333 Thread-12, WRITE: TLSv1 Application Data, length = 16404 Thread-12, WRITE: TLSv1 Application Data, length = 3697 Thread-12, READ: TLSv1 Application Data, length = 645 upload onReceiveStart: -1 download onReceived: delta: 334 bytes: 334 download onFinish Sep 28, 2012 8:36:13 AM com.sun.jersey.api.client.filter.LoggingFilter log INFO: 1 * Client in-bound response 1 < 200 1 < content-type: application/json 1 < Transfer-Encoding: chunked 1 < Set-Cookie: connect.sid=BS4OPYlxBXYxHFIrad8q3cSj.x5iTP%2Fm7UMNc8oR7CUisHwjVLSFN4dZprbkWlha5AQk; path=/; expires=Fri, 28 Sep 2012 04:36:18 GMT; httpOnly 1 < Connection: keep-alive 1 < X-Powered-By: Express 1 < [{"_id":"5064f1023785e3d91800000d","filename":"人题啊.png","contentType":"image/png","length":19813,"chunkSize":262144,"uploadDate":"2012-09-28T00:36:18.578Z","metadata":{"author":"6001011","status":"temp","lastModifiedDate":"2012-09-28T00:36:18.545Z"},"md5":"4ef5aad2a4a13b6e4729cc8456053af9","Server":"localhost","DB":"7001000"}] ******************** ={"_id":"5064f1023785e3d91800000d","chunkSize":262144,"md5":"4ef5aad2a4a13b6e4729cc8456053af9","length":19813,"DB":"7001000","filename":"人题啊.png","contentType":"image/png","uploadDate":"2012-09-28T00:36:18.578Z","Server":"localhost","metadata":{"author":"6001011","status":"temp","lastModifiedDate":"2012-09-28T00:36:18.545Z"}} Sep 28, 2012 8:36:17 AM com.sun.jersey.api.client.filter.LoggingFilter log INFO: 5 * Client out-bound request 5 > GET https://192.168.56.101:8000/itags/Tag/1036/editTag?jsonfile=%7B%22_id%22:%225064f1023785e3d91800000d%22,%22chunkSize%22:262144,%22md5%22:%224ef5aad2a4a13b6e4729cc8456053af9%22,%22length%22:19813,%22DB%22:%227001000%22,%22filename%22:%22%E4%BA%BA%E9%A2%98%E5%95%8A.png%22,%22contentType%22:%22image/png%22,%22uploadDate%22:%222012-09-28T00:36:18.578Z%22,%22Server%22:%22localhost%22,%22metadata%22:%7B%22author%22:%226001011%22,%22status%22:%22temp%22,%22lastModifiedDate%22:%222012-09-28T00:36:18.545Z%22%7D%7Dhttps://192.168.56.101:8000/itags/Tag/1036/editTag?jsonfile=%7B%22_id%22:%225064f1023785e3d91800000d%22,%22chunkSize%22:262144,%22md5%22:%224ef5aad2a4a13b6e4729cc8456053af9%22,%22length%22:19813,%22DB%22:%227001000%22,%22filename%22:%22%E4%BA%BA%E9%A2%98%E5%95%8A.png%22,%22contentType%22:%22image/png%22,%22uploadDate%22:%222012-09-28T00:36:18.578Z%22,%22Server%22:%22localhost%22,%22metadata%22:%7B%22author%22:%226001011%22,%22status%22:%22temp%22,%22lastModifiedDate%22:%222012-09-28T00:36:18.545Z%22%7D%7DThread-13, WRITE: TLSv1 Application Data, length = 703 Thread-13, READ: TLSv1 Application Data, length = 346 onReceiveStart: 10299 Thread-13, READ: TLSv1 Application Data, length = 10319 onReceived: delta: 8192 bytes: 8192 onReceived: delta: 2107 bytes: 10299 onFinish But in windows: Keep-Alive-Timer, called close() Keep-Alive-Timer, called closeInternal(true) Keep-Alive-Timer, SEND TLSv1 ALERT: warning, description = close_notify Keep-Alive-Timer, WRITE: TLSv1 Alert, length = 32 Keep-Alive-Timer, called closeSocket(selfInitiated) ******************** =人题啊.png form.getContentDisposition().getFileName() =人题啊.png Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 verify_data: { 242, 196, 62, 100, 237, 149, 2, 108, 226, 169, 30, 239 } *** %% Cached client session: [Session-3, TLS_RSA_WITH_AES_128_CBC_SHA] upload onSent: delta: 200 bytes: 200 WebUploadFile.this.totalBytes: 19813 upload onSent: delta: 8192 bytes: 8392 WebUploadFile.this.totalBytes: 19813 upload onSent: delta: 8192 bytes: 16584 WebUploadFile.this.totalBytes: 19813 upload onSent: delta: 3429 bytes: 20013 WebUploadFile.this.totalBytes: 19813 upload onSent: delta: 41 bytes: 20054 WebUploadFile.this.totalBytes: 19813 九月 28, 2012 8:29:21 上午 com.sun.jersey.api.client.filter.LoggingFilter log INFO: 1 * Client out-bound request 1 > POST https://192.168.56.101:8000/itags/uploadTagFile/10361 > Content-Type: multipart/form-data 1 > Accept: application/json --Boundary_1_14995509_1348792161365 Content-Type: image/png Content-Disposition: form-data; filename="人题啊.png"; modification-date="Sat, 09 Jun 2012 14:30:06 GMT"; size=19813; name="thumbnail" 塒NG --Boundary_1_14995509_1348792161365-- Thread-10, WRITE: TLSv1 Application Data, length = 3696 Thread-10, READ: TLSv1 Application Data, length = 32 Thread-10, READ: TLSv1 Application Data, length = 656 九月 28, 2012 8:29:21 上午 com.sun.jersey.api.client.filter.LoggingFilter log INFO: 1 * Client in-bound response 1 < 200 1 < content-type: application/json 1 < Transfer-Encoding: chunked 1 < Set-Cookie: connect.sid=qbUD2aJkbJB6VoS79xm0sN7d.oFnD5R%2BOMiXsX8Iv%2Fp8ItHb10aYc6M4Aom09WFsRdz4; path=/; expires=Fri, 28 Sep 2012 04:29:26 GMT; h ttpOnly 1 < Connection: keep-alive 1 < X-Powered-By: Express 1 < [{"_id":"5064ef663785e3d918000009","filename":"锟斤拷锟解啊.png","contentType":"image/png","length":19813,"chunkSize":262144,"uploadDate":"2012-09-28T 00:29:26.397Z","metadata":{"author":"6001011","status":"temp","lastModifiedDate":"2012-09-28T00:29:26.366Z"},"md5":"4ef5aad2a4a13b6e4729cc8456053af9", "Server":"localhost","DB":"7001000"}] upload onReceiveStart: -1 download onReceived: delta: 337 bytes: 337 download onFinish ******************** ={"_id":"5064ef663785e3d918000009","chunkSize":262144,"md5":"4ef5aad2a4a13b6e4729cc8456053af9","length":19813,"DB":"7001000","filename":"????.png","contentType":"image/png","uploadDate":"2012-09-28T00:29:26.397Z","Server":"localhost","metadata":{"author":"6001011","status":"temp ","lastModifiedDate":"2012-09-28T00:29:26.366Z"}} Keep-Alive-Timer, called close() Keep-Alive-Timer, called closeInternal(true) Keep-Alive-Timer, SEND TLSv1 ALERT: warning, description = close_notify Keep-Alive-Timer, WRITE: TLSv1 Alert, length = 32 Keep-Alive-Timer, called closeSocket(selfInitiated) Could you give me some direction on where the problem may be? Thanks, Brendan