Browse Source

修改下载文件接口

anderx 4 years ago
parent
commit
f1d11a675f

+ 3 - 2
src/main/java/com/goafanti/common/controller/PublicController.java

@@ -700,7 +700,8 @@ public class PublicController extends CertifyApiController {
            * @param delete 是否删除
            */
           @RequestMapping("/download")
-          public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
+          public void fileDownload(String fileName, Boolean delete,String aftName,
+								   HttpServletResponse response, HttpServletRequest request)
           {
               try
               {
@@ -712,7 +713,7 @@ public class PublicController extends CertifyApiController {
                   String filePath = uploadPath +"/"+ fileName;
 
                   response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
-                  FileUtils.setAttachmentResponseHeader(response, realFileName);
+                  FileUtils.setAttachmentResponseHeader(response, realFileName,aftName);
                   FileUtils.writeBytes(filePath, response.getOutputStream());
                   if(delete==null)delete=true;
                   if (delete)

+ 4 - 3
src/main/java/com/goafanti/common/utils/excel/FileUtils.java

@@ -185,13 +185,14 @@ public class FileUtils extends org.apache.commons.io.FileUtils
      * @param realFileName 真实文件名
      * @return
      */
-    public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException
+    public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName,String attFile) throws UnsupportedEncodingException
     {
         String percentEncodedFileName = percentEncode(realFileName);
 
         StringBuilder contentDispositionValue = new StringBuilder();
-        contentDispositionValue.append("attachment; filename=")
-                .append(percentEncodedFileName)
+        if(attFile!= null)contentDispositionValue.append("attachment; filename=");
+        else contentDispositionValue.append("attachment; filename=");
+        contentDispositionValue.append(percentEncodedFileName)
                 .append(";")
                 .append("filename*=")
                 .append("utf-8''")