Commit f975c4f6 by 段启岩

文件大小限制

parent f6017fdb
......@@ -4,10 +4,12 @@ import cn.meteor.beyondclouds.common.enums.ErrorCode;
import cn.meteor.beyondclouds.config.properties.BeyondCloudsProperties;
import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.core.exception.ServiceException;
import cn.meteor.beyondclouds.modules.resource.enums.FileUploadErrorCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
......@@ -36,7 +38,9 @@ public class GlobalExceptionHandler {
return Response.error(exception.getErrorCode(), exception.getErrorMsg());
} else if (e instanceof HttpRequestMethodNotSupportedException){
return Response.error(ErrorCode.OPERATION_FAILED.code(), e.getMessage());
} else {
} else if (e instanceof MaxUploadSizeExceededException) {
return Response.error(FileUploadErrorCode.MAXIMUM_UPLOAD_SIZE_EXCEEDED);
} {
if (debugMode) {
ByteArrayOutputStream byteBuff = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(byteBuff));
......
......@@ -8,7 +8,8 @@ import cn.meteor.beyondclouds.core.IErrorCode;
public enum FileUploadErrorCode implements IErrorCode {
UPLOAD_FAILURE(2001, "文件上传失败"),
UPLOAD_TYPE_ERROR(2002, "文件上传类型错误");
UPLOAD_TYPE_ERROR(2002, "文件上传类型错误"),
MAXIMUM_UPLOAD_SIZE_EXCEEDED(2003, "不能上传超过10MB的文件");
private long code;
private String msg;
......
......@@ -18,7 +18,32 @@ public enum UploadType {
/**
* 上传项目封面
*/
PROJECT_COVER(2, "project/cover/");
PROJECT_COVER(2, "project/cover/"),
/**
* 上传动态图片
*/
TRENDS_IMAGES(3, "trends/images/"),
/**
* 上传内容图片
*/
BLOG_IMAGES(4, "blog/images/"),
/**
* 上传项目内容图片
*/
PROJECT_IMAGES(5, "project/images/"),
/**
* 上传问答内容图片
*/
QUESTION_IMAGES(6, "question/images/"),
/**
* 上传CMS内容图片
*/
CMS_IMAGES(100, "cms/images/");
private int ordinal;
private String basePath;
......
......@@ -46,6 +46,15 @@ spring:
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
server:
tomcat:
max-swallow-size: 100MB
# swagger
swagger:
enable: true
......
......@@ -46,6 +46,15 @@ spring:
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
server:
tomcat:
max-swallow-size: 100MB
# swagger
swagger:
enable: true
......
spring:
# 数据源
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
......@@ -45,6 +44,14 @@ spring:
enable-auto-commit: true
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
server:
tomcat:
max-swallow-size: 100MB
# swagger
swagger:
......
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