Selaa lähdekoodia

3.0.1-下载附件名乱码问题修复

xiaof 3 vuotta sitten
vanhempi
commit
0b7451a160

+ 2 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/AttachmentCommonServiceImpl.java

@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
+import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.List;
@@ -236,7 +237,6 @@ public class AttachmentCommonServiceImpl implements AttachmentCommonService {
 
     public static void outputFile(HttpServletResponse response, File file, String fileName) {
         try {
-
             if (!file.exists()) {
                 response.sendError(404, "File not found!");
             }
@@ -245,7 +245,7 @@ public class AttachmentCommonServiceImpl implements AttachmentCommonService {
             byte[] buf = new byte[1024];
             int len = 0;
 
-            String fName = new String(fileName.getBytes(), StandardCharsets.UTF_8);
+            String fName = URLEncoder.encode(fileName, "UTF-8");
 
             response.reset();
             response.setContentType("application/x-msdownload");