[英]Upload XLSX or ZIP file using Apache CXF corrupts the file
I am trying to upload an XLSX file and the file gets corrupted once it reaches the server 我正在尝试上传XLSX文件,并且一旦到达服务器,文件就会损坏
Good file N c A wo]6 9)} "r F1 6 a8 E p , i 9J ~ 6ʒ 2 y b ɵz` E ne 好的文件``N.c.A.wo] 6.9)}“r F1 6 a8 E p , i 9J 〜 6 2。 yy b ɵz` E ne。
Bad file ( after upload) N c A wo]6 9)} "r F1 6 a8 E p , i 9J ~ 6ʒ 2 y b ɵz` E ne 错误的文件(上传后)n 2 y b z E ne。
Client side JS to upload this file 客户端JS上传此文件
var formData = new FormData(); formData.append('file',$('input[type=file]')[0].files[0]); $.ajax({ url: 'upload', data: formData, type: 'POST', enctype: "multipart/form-data", processData: false });
and at the server side using apache CXF 并在服务器端使用apache CXF
@POST @Path("/upload") @Consumes(MediaType.MULTIPART_FORM_DATA) public void upload (@Multipart("file") Attachment attachment){ InputStream inputStream = attachment.getDataHandler().getInputStream(); File targetFile = new File("D://test.xlsx"); OutputStream outStream = new FileOutputStream(targetFile); int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { outStream.write(bytes, 0, read); } outStream.close(); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.