优化文件上传配置和校验
This commit is contained in:
@@ -100,13 +100,13 @@ public class SysBaseController {
|
||||
|
||||
@Operation(summary = "取消忽略脱敏")
|
||||
@GetMapping("/unignore-mask")
|
||||
public Result<Boolean> unIgnoreMask(HttpServletRequest request) {
|
||||
public Result<Boolean> unIgnoreMask() {
|
||||
return sysBaseService.unIgnoreMask();
|
||||
}
|
||||
|
||||
@Operation(summary = "退出登录")
|
||||
@GetMapping("/logout")
|
||||
public Result<Boolean> logout(HttpServletRequest request) {
|
||||
public Result<Boolean> logout() {
|
||||
LoginUserDto loginUser = AuthUtils.get();
|
||||
AuthUtils.remove(loginUser.getId());
|
||||
return Result.ok(true);
|
||||
|
||||
@@ -32,9 +32,8 @@ import xtools.boot.api.model.dto.Result;
|
||||
import xtools.boot.api.model.dto.page.PageReq;
|
||||
import xtools.boot.api.model.dto.page.PageResp;
|
||||
import xtools.boot.api.model.dto.req.IdListReq;
|
||||
import xtools.core.StringUtils;
|
||||
import xtools.core.extend.CheckUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
@@ -95,32 +94,25 @@ public class SysNoticeController {
|
||||
@Operation(summary = "上传图片")
|
||||
@PostMapping("/upload-img")
|
||||
public Result<Long> uploadImg(
|
||||
@Schema(description = "图片文件")
|
||||
@RequestParam("img") MultipartFile img
|
||||
) {
|
||||
if (img.isEmpty()) {
|
||||
throw new BizError("图片件不能为空");
|
||||
}
|
||||
String filename = img.getOriginalFilename();
|
||||
if (StringUtils.isBlank(filename)) {
|
||||
throw new BizError("图片件名称不能为空");
|
||||
}
|
||||
FileBizEnum bizType = FileBizEnum.SYS_NOTICE;
|
||||
if (!CheckUtils.suffix(filename, bizType.extArr())) {
|
||||
throw new BizError("图片格式错误");
|
||||
}
|
||||
try (InputStream inputStream = img.getInputStream()) {
|
||||
LoginUserDto loginUser = AuthUtils.get();
|
||||
Long id = sysFileOptService.upload(
|
||||
filename,
|
||||
img.getOriginalFilename(),
|
||||
inputStream,
|
||||
img.getSize(),
|
||||
loginUser.getId(),
|
||||
loginUser.getAccount(),
|
||||
bizType,
|
||||
FileBizEnum.SYS_NOTICE,
|
||||
null
|
||||
);
|
||||
return Result.ok(id);
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
log.error("上传失败", e);
|
||||
throw new BizError("上传失败");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user