|
|
@ -52,32 +52,71 @@ public class CommonController |
|
|
|
* 通用下载请求 |
|
|
|
* |
|
|
|
* @param fileName 文件名称 |
|
|
|
* @param delete 是否删除 |
|
|
|
* 必须登录才可以下载 |
|
|
|
* |
|
|
|
*/ |
|
|
|
@SaCheckLogin |
|
|
|
@GetMapping("common/download") |
|
|
|
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) |
|
|
|
public void fileDownload(String fileUrl,String fileName, HttpServletResponse response, HttpServletRequest request) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
|
|
|
|
String uploadType = JianweiConfig.getUploadType(); |
|
|
|
|
|
|
|
|
|
|
|
if (uploadType.equals("disk")) { |
|
|
|
// 本地资源路径
|
|
|
|
String localPath = JianweiConfig.getProfile(); |
|
|
|
// 数据库资源地址
|
|
|
|
String downloadPath = localPath + StringUtils.substringAfter(fileName, 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)); |
|
|
|
FileUtils.writeBytes(downloadPath, response.getOutputStream()); |
|
|
|
} else { |
|
|
|
|
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
response.setContentType("multipart/form-data"); |
|
|
|
response.setHeader("Content-Disposition", |
|
|
|
"attachment;fileName=" + fileName); |
|
|
|
ServletOutputStream outputStream=null; |
|
|
|
try { |
|
|
|
outputStream = response.getOutputStream(); |
|
|
|
byte[] bytes = fastdfs.downloadFile(fileUrl); |
|
|
|
IOUtils.write(bytes,response.getOutputStream()); |
|
|
|
} catch (Exception e){ |
|
|
|
throw new BaseException("文件下载失败"); |
|
|
|
}finally { |
|
|
|
if (outputStream!=null) { |
|
|
|
try { |
|
|
|
outputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new BaseException("文件下载失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// if (!FileUtils.isValidFilename(fileName))
|
|
|
|
// {
|
|
|
|
// throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
|
|
|
// }
|
|
|
|
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); |
|
|
|
/* String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); |
|
|
|
String filePath = JianweiConfig.getDownloadPath() + fileName; |
|
|
|
|
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
response.setContentType("multipart/form-data"); |
|
|
|
response.setHeader("Content-Disposition", |
|
|
|
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName)); |
|
|
|
FileUtils.writeBytes(filePath, response.getOutputStream()); |
|
|
|
if (delete) |
|
|
|
FileUtils.writeBytes(filePath, response.getOutputStream());*/ |
|
|
|
/*if (delete) |
|
|
|
{ |
|
|
|
FileUtils.deleteFile(filePath); |
|
|
|
} |
|
|
|
}*/ |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|