新增:新增上传头像 API,采用本地存储方式存储头像

This commit is contained in:
2023-01-05 22:32:23 +08:00
parent e77c77419b
commit 5252c54c48
54 changed files with 931 additions and 937 deletions

View File

@@ -33,8 +33,10 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import cn.dev33.satoken.exception.NotLoginException;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import top.charles7c.cnadmin.common.exception.BadRequestException;
@@ -164,6 +166,18 @@ public class GlobalExceptionHandler {
return R.fail(HttpStatus.UNAUTHORIZED.value(), "认证失败,无法访问系统资源");
}
/**
* 拦截文件上传异常-超过上传大小限制
*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MaxUploadSizeExceededException.class)
public R handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e, HttpServletRequest request) {
String sizeLimit = StrUtil.subBetween(e.getMessage(), "The maximum size ", " for");
log.error("请求地址'{}',上传文件失败,文件大小超过限制", request.getRequestURI(), e);
return R.fail(HttpStatus.BAD_REQUEST.value(),
String.format("请上传小于 %s MB 的文件", NumberUtil.parseLong(sizeLimit) / 1024 / 1024));
}
/**
* 操作日志保存异常信息
*