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