|
@@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -18,6 +19,10 @@ import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
|
import com.ruoyi.common.utils.file.FileUtils;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+
|
|
|
/**
|
|
|
* 通用请求处理
|
|
|
*
|
|
@@ -49,10 +54,9 @@ public class CommonController
|
|
|
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
|
|
String filePath = Global.getDownloadPath() + fileName;
|
|
|
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
- response.setContentType("multipart/form-data");
|
|
|
- response.setHeader("Content-Disposition",
|
|
|
- "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+ FileUtils.setAttachmentResponseHeader(response,realFileName);
|
|
|
+
|
|
|
FileUtils.writeBytes(filePath, response.getOutputStream());
|
|
|
if (delete)
|
|
|
{
|
|
@@ -103,10 +107,10 @@ public class CommonController
|
|
|
String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
|
|
|
// 下载名称
|
|
|
String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
- response.setContentType("multipart/form-data");
|
|
|
- response.setHeader("Content-Disposition",
|
|
|
- "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));
|
|
|
+
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+ FileUtils.setAttachmentResponseHeader(response,downloadName);
|
|
|
+
|
|
|
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
|
|
}
|
|
|
}
|