文件下载 重命名优化
This commit is contained in:
parent
fc207d9489
commit
fe1fe00ecb
@ -106,13 +106,15 @@ export function selectMoeDictLabel(datas, value) {
|
||||
}
|
||||
|
||||
// 通用下载方法
|
||||
export function download(fileName) {
|
||||
export function download(fileName, fileUrlPath) {
|
||||
window.location.href =
|
||||
baseURL +
|
||||
"/common/download?fileName=" +
|
||||
encodeURI(fileName) +
|
||||
"&fileUrlPath=" +
|
||||
encodeURI(fileUrlPath) +
|
||||
"&delete=" +
|
||||
true;
|
||||
false;
|
||||
}
|
||||
|
||||
// 字符串格式化(%s )
|
||||
|
@ -187,7 +187,8 @@ export default {
|
||||
//下载
|
||||
handleDown(row) {
|
||||
var url = row.fileurl;
|
||||
window.open(this.apiurl + url);
|
||||
//window.open(this.apiurl + url);
|
||||
this.download(row.name,row.fileurl);
|
||||
},
|
||||
//预览
|
||||
handleView(row) {
|
||||
|
@ -106,6 +106,14 @@ public class RuoYiConfig
|
||||
return getProfile() + "/download/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下载路径
|
||||
*/
|
||||
public static String getDownuploadPath()
|
||||
{
|
||||
return getProfile() + "/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上传路径
|
||||
*/
|
||||
|
@ -54,22 +54,25 @@ public class CommonController {
|
||||
* @param delete 是否删除
|
||||
*/
|
||||
@GetMapping("common/download")
|
||||
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
|
||||
public void fileDownload(String fileName,String fileUrlPath ,Boolean delete, HttpServletResponse response, HttpServletRequest request) {
|
||||
try {
|
||||
if (!FileUtils.isValidFilename(fileName)) {
|
||||
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
||||
}
|
||||
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
||||
String filePath = RuoYiConfig.getDownloadPath() + fileName;
|
||||
//String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
||||
String filePath = RuoYiConfig.getDownuploadPath() + fileUrlPath;
|
||||
filePath=filePath.replace("/profile/","");
|
||||
|
||||
System.out.println("filepath"+filePath);
|
||||
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("multipart/form-data");
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
|
||||
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, fileName));
|
||||
FileUtils.writeBytes(filePath, response.getOutputStream());
|
||||
if (delete) {
|
||||
FileUtils.deleteFile(filePath);
|
||||
}
|
||||
// if (delete) {
|
||||
// FileUtils.deleteFile(filePath);
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
log.error("下载文件失败", e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user