提交 45acbaf6 authored 作者: kxjia's avatar kxjia

文件上传

上级 927ba71d
...@@ -4,6 +4,7 @@ import org.jeecg.common.util.DateUtils; ...@@ -4,6 +4,7 @@ import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.stm.baosong.entity.BaosongTask; import org.jeecg.modules.stm.baosong.entity.BaosongTask;
import org.jeecg.modules.stm.baosong.entity.BaosongTpl; import org.jeecg.modules.stm.baosong.entity.BaosongTpl;
import org.jeecg.modules.stm.utils.DirectoryUtil;
import org.w3c.dom.Comment; import org.w3c.dom.Comment;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
...@@ -107,9 +108,17 @@ public class CreateXmlFile { ...@@ -107,9 +108,17 @@ public class CreateXmlFile {
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource source = new DOMSource(doc); DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(filePath));
transformer.transform(source, result); String dirPath = filePath.substring(0,filePath.lastIndexOf("/"));
System.out.println("XML 文件生成成功!"); Boolean pathIsEsixt = DirectoryUtil.ensureDirectoryExists(dirPath);
if(pathIsEsixt) {
StreamResult result = new StreamResult(new File(filePath));
transformer.transform(source, result);
System.out.println("XML 文件生成成功!");
} else {
System.out.println("XML 生成失败");
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -25,6 +25,8 @@ import org.springframework.web.servlet.ModelAndView; ...@@ -25,6 +25,8 @@ import org.springframework.web.servlet.ModelAndView;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.util.HashMap;
import java.util.Map;
/** /**
* <p> * <p>
...@@ -99,6 +101,50 @@ public class CommonController { ...@@ -99,6 +101,50 @@ public class CommonController {
return result; return result;
} }
@PostMapping(value = "/upload35")
public Result<?> upload35(HttpServletRequest request, HttpServletResponse response) throws Exception {
Result<?> result = new Result<>();
String savePath = "";
String bizPath = request.getParameter("biz");
String uuid = request.getParameter("uuid");
Map<String,Object> retData = new HashMap<>();
retData.put("uuid",uuid);
//LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞
if (oConvertUtils.isNotEmpty(bizPath)) {
if(bizPath.contains(SymbolConstant.SPOT_SINGLE_SLASH) || bizPath.contains(SymbolConstant.SPOT_DOUBLE_BACKSLASH)){
throw new JeecgBootException("上传目录bizPath,格式非法!");
}
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// 获取上传文件对象
MultipartFile file = multipartRequest.getFile("file");
if(oConvertUtils.isEmpty(bizPath)){
if(CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)){
bizPath = "upload";
}else{
bizPath = "";
}
}
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
savePath = this.uploadLocal(file,bizPath);
}else{
savePath = CommonUtils.upload(file, bizPath, uploadType);
}
if(oConvertUtils.isNotEmpty(savePath)){;
retData.put("author","");
retData.put("detail",new HashMap());
retData.put("url",savePath);
return Result.ok(retData,savePath);
}else {
result.setMessage("上传失败!");
result.setSuccess(false);
return result;
}
}
/** /**
* 本地文件上传 * 本地文件上传
* @param mf 文件 * @param mf 文件
...@@ -231,63 +277,63 @@ public class CommonController { ...@@ -231,63 +277,63 @@ public class CommonController {
} }
// /** /**
// * 下载文件 * 下载文件
// * 请求地址:http://localhost:8080/common/download/{user/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg} * 请求地址:http://localhost:8080/common/download/{user/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg}
// * *
// * @param request * @param request
// * @param response * @param response
// * @throws Exception * @throws Exception
// */ */
// @GetMapping(value = "/download/**") @GetMapping(value = "/download/**")
// public void download(HttpServletRequest request, HttpServletResponse response) throws Exception { public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
// // ISO-8859-1 ==> UTF-8 进行编码转换 // ISO-8859-1 ==> UTF-8 进行编码转换
// String filePath = extractPathFromPattern(request); String filePath = extractPathFromPattern(request);
// // 其余处理略 // 其余处理略
// InputStream inputStream = null; InputStream inputStream = null;
// OutputStream outputStream = null; OutputStream outputStream = null;
// try { try {
// filePath = filePath.replace("..", ""); filePath = filePath.replace("..", "");
// if (filePath.endsWith(",")) { if (filePath.endsWith(",")) {
// filePath = filePath.substring(0, filePath.length() - 1); filePath = filePath.substring(0, filePath.length() - 1);
// } }
// String localPath = uploadpath; String localPath = uploadpath;
// String downloadFilePath = localPath + File.separator + filePath; String downloadFilePath = localPath + File.separator + filePath;
// File file = new File(downloadFilePath); File file = new File(downloadFilePath);
// if (file.exists()) { if (file.exists()) {
// response.setContentType("application/force-download");// 设置强制下载不打开             response.setContentType("application/force-download");// 设置强制下载不打开            
// response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1")); response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
// inputStream = new BufferedInputStream(new FileInputStream(file)); inputStream = new BufferedInputStream(new FileInputStream(file));
// outputStream = response.getOutputStream(); outputStream = response.getOutputStream();
// byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
// int len; int len;
// while ((len = inputStream.read(buf)) > 0) { while ((len = inputStream.read(buf)) > 0) {
// outputStream.write(buf, 0, len); outputStream.write(buf, 0, len);
// } }
// response.flushBuffer(); response.flushBuffer();
// } }
//
// } catch (Exception e) { } catch (Exception e) {
// log.info("文件下载失败" + e.getMessage()); log.info("文件下载失败" + e.getMessage());
// // e.printStackTrace(); // e.printStackTrace();
// } finally { } finally {
// if (inputStream != null) { if (inputStream != null) {
// try { try {
// inputStream.close(); inputStream.close();
// } catch (IOException e) { } catch (IOException e) {
// e.printStackTrace(); e.printStackTrace();
// } }
// } }
// if (outputStream != null) { if (outputStream != null) {
// try { try {
// outputStream.close(); outputStream.close();
// } catch (IOException e) { } catch (IOException e) {
// e.printStackTrace(); e.printStackTrace();
// } }
// } }
// } }
//
// } }
/** /**
* @功能:pdf预览Iframe * @功能:pdf预览Iframe
......
...@@ -12,7 +12,6 @@ import jakarta.servlet.http.HttpServletRequest; ...@@ -12,7 +12,6 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CacheConstant; import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.CommonConstant;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论