Commit 4c909922 authored by 赵啸非's avatar 赵啸非

取消网关的日志拦截

parent 169b88ad
...@@ -2,6 +2,7 @@ package com.mortals.xhx.base.system.upload.service.impl; ...@@ -2,6 +2,7 @@ package com.mortals.xhx.base.system.upload.service.impl;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
...@@ -43,7 +44,6 @@ public class UploadServiceImpl implements UploadService { ...@@ -43,7 +44,6 @@ public class UploadServiceImpl implements UploadService {
private String filePath; private String filePath;
@Override @Override
public String saveFileUpload(MultipartFile tempFile, String prePath, IUser user) { public String saveFileUpload(MultipartFile tempFile, String prePath, IUser user) {
if (tempFile == null || tempFile.getSize() == 0) { if (tempFile == null || tempFile.getSize() == 0) {
...@@ -72,12 +72,16 @@ public class UploadServiceImpl implements UploadService { ...@@ -72,12 +72,16 @@ public class UploadServiceImpl implements UploadService {
File uploadFile = new File(filePathAll); File uploadFile = new File(filePathAll);
try { try {
log.info("文件正在储存,filepath:"+filePathAll); log.info("文件正在储存,filepath:" + filePathAll);
tempFile.transferTo(uploadFile); tempFile.transferTo(uploadFile);
} catch (Exception e) { } catch (Exception e) {
throw new AppException(e.getMessage()); throw new AppException(e.getMessage());
} }
boolean bool = StrUtil.startWith(prePath, "/");
if (!bool) {
prePath = "/" + prePath;
}
return (StringUtils.isEmpty(prePath) ? "" : prePath + "/") + newName; return (StringUtils.isEmpty(prePath) ? "" : prePath + "/") + newName;
} }
...@@ -103,7 +107,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -103,7 +107,7 @@ public class UploadServiceImpl implements UploadService {
@Override @Override
public void preview(String fileName, HttpServletResponse response) { public void preview(String fileName, HttpServletResponse response) {
String filePath = this.filePath+"/file/preview/" + fileName; String filePath = this.filePath + "/file/preview/" + fileName;
try { try {
response.setContentType(MediaType.IMAGE_JPEG_VALUE); response.setContentType(MediaType.IMAGE_JPEG_VALUE);
setAttachmentResponseHeader(response, fileName); setAttachmentResponseHeader(response, fileName);
...@@ -117,12 +121,11 @@ public class UploadServiceImpl implements UploadService { ...@@ -117,12 +121,11 @@ public class UploadServiceImpl implements UploadService {
/** /**
* 下载文件名重新编码 * 下载文件名重新编码
* *
* @param response 响应对象 * @param response 响应对象
* @param realFileName 真实文件名 * @param realFileName 真实文件名
* @return * @return
*/ */
public void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException public void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException {
{
String percentEncodedFileName = percentEncode(realFileName); String percentEncodedFileName = percentEncode(realFileName);
StringBuilder contentDispositionValue = new StringBuilder(); StringBuilder contentDispositionValue = new StringBuilder();
...@@ -142,8 +145,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -142,8 +145,7 @@ public class UploadServiceImpl implements UploadService {
* @param s 需要百分号编码的字符串 * @param s 需要百分号编码的字符串
* @return 百分号编码后的字符串 * @return 百分号编码后的字符串
*/ */
public String percentEncode(String s) throws UnsupportedEncodingException public String percentEncode(String s) throws UnsupportedEncodingException {
{
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString()); String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString());
return encode.replaceAll("\\+", "%20"); return encode.replaceAll("\\+", "%20");
} }
...@@ -151,7 +153,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -151,7 +153,7 @@ public class UploadServiceImpl implements UploadService {
@Override @Override
public void uploadDownload(String fileName, HttpServletResponse response) { public void uploadDownload(String fileName, HttpServletResponse response) {
String filePath = this.filePath+ fileName; String filePath = this.filePath + fileName;
try { try {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
setAttachmentResponseHeader(response, fileName); setAttachmentResponseHeader(response, fileName);
...@@ -163,7 +165,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -163,7 +165,7 @@ public class UploadServiceImpl implements UploadService {
@Override @Override
public void deleteFile(String fileName) { public void deleteFile(String fileName) {
String filePath = this.filePath+ fileName; String filePath = this.filePath + fileName;
try { try {
FileUtil.del(filePath); FileUtil.del(filePath);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -52,7 +52,7 @@ public class UploadController extends BaseController { ...@@ -52,7 +52,7 @@ public class UploadController extends BaseController {
@RequestMapping(value = "commonupload") @RequestMapping(value = "commonupload")
public String doFileUpload(MultipartFile file, @RequestParam(value = "prePath",defaultValue = "file/fileupload") String prePath) { public String doFileUpload(MultipartFile file, @RequestParam(value = "prePath",defaultValue = "/file/fileupload") String prePath) {
Map<String, Object> model = new HashMap<>(); Map<String, Object> model = new HashMap<>();
String jsonStr = ""; String jsonStr = "";
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment