|
@@ -8,6 +8,8 @@ import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -72,7 +74,8 @@ public class CommonController {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@PostMapping(value = "/upload")
|
|
@PostMapping(value = "/upload")
|
|
- public Result<?> upload(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
|
+ public Map<String,Object> upload(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
Result<?> result = new Result<>();
|
|
Result<?> result = new Result<>();
|
|
String savePath = "";
|
|
String savePath = "";
|
|
String bizPath = request.getParameter("biz");
|
|
String bizPath = request.getParameter("biz");
|
|
@@ -82,7 +85,7 @@ public class CommonController {
|
|
if(CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)){
|
|
if(CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)){
|
|
result.setMessage("使用阿里云文件上传时,必须添加目录!");
|
|
result.setMessage("使用阿里云文件上传时,必须添加目录!");
|
|
result.setSuccess(false);
|
|
result.setSuccess(false);
|
|
- return result;
|
|
|
|
|
|
+ return map;
|
|
}else{
|
|
}else{
|
|
bizPath = "";
|
|
bizPath = "";
|
|
}
|
|
}
|
|
@@ -99,7 +102,11 @@ public class CommonController {
|
|
result.setMessage("上传失败!");
|
|
result.setMessage("上传失败!");
|
|
result.setSuccess(false);
|
|
result.setSuccess(false);
|
|
}
|
|
}
|
|
- return result;
|
|
|
|
|
|
+ map.put("code",0);
|
|
|
|
+ Map<String,Object> map1=new HashMap<>();
|
|
|
|
+ map1.put("url","http://localhost:3000/jeecg-boot/sys/common/upload/");
|
|
|
|
+ map.put("data",map1);
|
|
|
|
+ return map;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -374,6 +381,13 @@ public class CommonController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @Author chenchuang
|
|
|
|
+ * @Description //TODO 常用文件上传下载
|
|
|
|
+ * @Date 2021/6/23 15:42
|
|
|
|
+ * @Param [request, response]
|
|
|
|
+ * @return org.jeecg.common.api.vo.Result
|
|
|
|
+ */
|
|
@PostMapping(value = "/uploadFile")
|
|
@PostMapping(value = "/uploadFile")
|
|
public Result uploadFile(HttpServletRequest request, HttpServletResponse response) {
|
|
public Result uploadFile(HttpServletRequest request, HttpServletResponse response) {
|
|
Result result = new Result<>();
|
|
Result result = new Result<>();
|
|
@@ -388,6 +402,9 @@ public class CommonController {
|
|
}
|
|
}
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
MultipartFile mf = multipartRequest.getFile("file");// 获取上传文件对象
|
|
MultipartFile mf = multipartRequest.getFile("file");// 获取上传文件对象
|
|
|
|
+ if(mf==null){
|
|
|
|
+ mf = multipartRequest.getFile("image");// 获取上传文件对象
|
|
|
|
+ }
|
|
String orgName = mf.getOriginalFilename();// 获取文件名
|
|
String orgName = mf.getOriginalFilename();// 获取文件名
|
|
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
|
|
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
|
|
String savePath = file.getPath() + File.separator + fileName;
|
|
String savePath = file.getPath() + File.separator + fileName;
|
|
@@ -407,4 +424,55 @@ public class CommonController {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @Author chenchuang
|
|
|
|
+ * @Description //TODO 自定义表单文件上传下载
|
|
|
|
+ * @Date 2021/6/23 15:42
|
|
|
|
+ * @Param [request, response]
|
|
|
|
+ * @return java.lang.Object
|
|
|
|
+ */
|
|
|
|
+ @PostMapping(value = "/uploadFile2")
|
|
|
|
+ public Object uploadFile2(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ Map<String,Object> map =new HashMap<>();
|
|
|
|
+ Result result = new Result<>();
|
|
|
|
+ try {
|
|
|
|
+ String ctxPath = uploadpath;
|
|
|
|
+ String fileName = null;
|
|
|
|
+ String bizPath = "file";
|
|
|
|
+ String nowday = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
|
|
|
+ File file = new File(ctxPath + File.separator + bizPath + File.separator + nowday);
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ file.mkdirs();// 创建文件根目录
|
|
|
|
+ }
|
|
|
|
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
|
+ MultipartFile mf = multipartRequest.getFile("file");// 获取上传文件对象
|
|
|
|
+ if(mf==null){
|
|
|
|
+ mf = multipartRequest.getFile("image");// 获取上传文件对象
|
|
|
|
+ }
|
|
|
|
+ String orgName = mf.getOriginalFilename();// 获取文件名
|
|
|
|
+ fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
|
|
|
|
+ String savePath = file.getPath() + File.separator + fileName;
|
|
|
|
+ File savefile = new File(savePath);
|
|
|
|
+ FileCopyUtils.copy(mf.getBytes(), savefile);
|
|
|
|
+ String dbpath = bizPath + File.separator + nowday + File.separator + fileName;
|
|
|
|
+ if (dbpath.contains("\\")) {
|
|
|
|
+ dbpath = dbpath.replace("\\", "/");
|
|
|
|
+ }
|
|
|
|
+ result.setMessage(dbpath);
|
|
|
|
+ result.setSuccess(true);
|
|
|
|
+ map.put("message",dbpath);
|
|
|
|
+ map.put("success",true);
|
|
|
|
+ map.put("code",0);
|
|
|
|
+ Map<String,Object> map1=new HashMap<>();
|
|
|
|
+ map1.put("url","http://localhost:3000/jeecg-boot/sys/common/downloadFile/"+dbpath);
|
|
|
|
+ map.put("data",map1);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ map.put("success",false);
|
|
|
|
+ map.put("message",e.getMessage());
|
|
|
|
+ result.setSuccess(false);
|
|
|
|
+ result.setMessage(e.getMessage());
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
}
|
|
}
|