调试 文件无法访问问题

This commit is contained in:
YuanFeng 2024-10-09 00:51:42 +08:00
parent 4012c53116
commit 7b3dbb71ca
1 changed files with 3 additions and 0 deletions

View File

@ -59,6 +59,8 @@ public class FileTypeUtils {
* @param content 附件内容
*/
public static void writeAttachment(HttpServletResponse response, String filename, byte[] content) throws IOException {
System.out.println("filename@@"+filename);
System.out.println("filename@@length"+content.length);
// 设置 header contentType
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
String contentType = getMineType(content, filename);
@ -69,6 +71,7 @@ public class FileTypeUtils {
response.setHeader("Content-Range", String.valueOf(content.length - 1));
response.setHeader("Accept-Ranges", "bytes");
}
if (contentType.startsWith("image/")) {
// 设置缓存
response.setHeader("Cache-Control", "max-age=604800");