fix: mvc 响应 文件时,对 filename 进行 url 编码
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
package net.geedge.asw.common.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import com.j256.simplemagic.ContentInfo;
|
||||
import com.j256.simplemagic.ContentInfoUtil;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.j256.simplemagic.ContentInfo;
|
||||
import com.j256.simplemagic.ContentInfoUtil;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class ResponseUtil {
|
||||
|
||||
@@ -25,7 +24,7 @@ public class ResponseUtil {
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void downloadFile(HttpServletResponse response, String contentType, String filename, byte[] data) throws IORuntimeException, IOException {
|
||||
String fileName = T.URLUtil.encode(filename, T.CharsetUtil.CHARSET_UTF_8);
|
||||
String fileName = URLEncoder.encode(filename, "UTF-8");
|
||||
ReflectUtil.invoke(response, "addHeader", "Content-Disposition", "attachment; filename=" + fileName);
|
||||
ReflectUtil.invoke(response, "addHeader", "Content-Length", "" + data.length);
|
||||
ReflectUtil.invoke(response, "setHeader", "Access-Control-Expose-Headers", "Content-Disposition");
|
||||
@@ -46,7 +45,7 @@ public class ResponseUtil {
|
||||
public static void downloadFile(HttpServletResponse response, String filename, byte[] data)
|
||||
throws IORuntimeException, IOException {
|
||||
response.setContentType(ResponseUtil.getDownloadContentType(filename));
|
||||
String fileName = T.URLUtil.encode(filename, T.CharsetUtil.CHARSET_UTF_8);
|
||||
String fileName = URLEncoder.encode(filename, "UTF-8");
|
||||
// response.addHeader("Content-Disposition", "attachment; filename=" + fileName);
|
||||
// response.addHeader("Content-Length", "" + data.length);
|
||||
// response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
|
||||
Reference in New Issue
Block a user