簡體   English   中英

使用Apache CXF上傳XLSX或ZIP文件會損壞文件

[英]Upload XLSX or ZIP file using Apache CXF corrupts the file

我正在嘗試上傳XLSX文件,並且一旦到達服務器,文件就會損壞

好的文件``N.c.A.wo] 6.9)}“r F1 6 a8 E p , i 9J 〜 6 2。 yy b ɵz` E ne。

錯誤的文件(上傳后)n 2 y b z E ne。

客戶端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 }); 

並在服務器端使用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(); } 

  1. CXF沒有問題
  2. JS庫沒有問題
  3. 我們有一個轉換器進行編碼,因此根據@Galigator的上述評論,很明顯它是一個編碼問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM