|
|
|
@ -35,6 +35,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
@ -295,7 +297,7 @@ public class SysFileController extends CoreBaseController {
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/download/{id}")
|
|
|
|
|
@ApiOperation(value = "文件下载", notes = "文件下载")
|
|
|
|
|
public void singleDownload(@PathVariable("id") String id, HttpServletResponse response) {
|
|
|
|
|
public void singleDownload(@PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
try {
|
|
|
|
|
startMultiService();
|
|
|
|
|
|
|
|
|
@ -320,8 +322,19 @@ public class SysFileController extends CoreBaseController {
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String userAgent = request.getHeader("User-Agent");
|
|
|
|
|
String formFileName = sysFile.getFileOriginalName();
|
|
|
|
|
|
|
|
|
|
// 针对IE或者以IE为内核的浏览器:
|
|
|
|
|
if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
|
|
|
|
|
formFileName = java.net.URLEncoder.encode(formFileName, "UTF-8");
|
|
|
|
|
} else {
|
|
|
|
|
// 非IE浏览器的处理:
|
|
|
|
|
formFileName = new String(formFileName.getBytes("UTF-8"), "ISO-8859-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.setContentType("application/force-download"); // 设置强制下载不打开
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + sysFile.getFileOriginalName()); // 设置文件名
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + formFileName); // 设置文件名
|
|
|
|
|
response.addHeader("Content-type", FileContentTypeTool.getContentType(StringTool.getStringFileSuffix(sysFile.getFileOriginalName(), true))); // 设置文件名
|
|
|
|
|
|
|
|
|
|
BufferedInputStream bis = null;
|
|
|
|
|