上传文件文件名称长度校验处理
This commit is contained in:
parent
b1b1ac0c3e
commit
d2996c73e2
@ -6,6 +6,7 @@ import cn.axzo.framework.auth.domain.ContextInfoHolder;
|
||||
import cn.axzo.oss.client.vo.FileInformationVo;
|
||||
import cn.axzo.oss.client.vo.FindFileUrlVo;
|
||||
import cn.axzo.oss.client.vo.WebFileUploadVo;
|
||||
import cn.axzo.oss.common.exception.BizException;
|
||||
import cn.axzo.oss.common.utils.BeanConvertUtil;
|
||||
import cn.axzo.oss.manager.api.dto.request.FindFileUrlDto;
|
||||
import cn.axzo.oss.manager.api.dto.request.ServerFileDownloadDto;
|
||||
@ -18,6 +19,7 @@ import cn.axzo.oss.service.api.FileService;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -28,6 +30,8 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.axzo.oss.common.enums.CodeEnum.FILE_NAME_TOO_LONG;
|
||||
|
||||
/**
|
||||
* 前端文件controller
|
||||
*
|
||||
@ -37,6 +41,8 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/webApi")
|
||||
public class WebFileController {
|
||||
|
||||
private static int FILE_NAME_MAX_LENGTH = 128;
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
@ -52,10 +58,12 @@ public class WebFileController {
|
||||
if (contextInfo != null) {
|
||||
liteSaasContext = contextInfo.lite();
|
||||
}
|
||||
String filename = file.getOriginalFilename();
|
||||
BizException.error(filename.length() > FILE_NAME_MAX_LENGTH, FILE_NAME_TOO_LONG);
|
||||
ServerFileUploadDto fileUploadDto = ServerFileUploadDto.builder()
|
||||
.appCode(appCode)
|
||||
.bizScene(bizScene)
|
||||
.fileName(file.getOriginalFilename())
|
||||
.fileName(filename)
|
||||
.fileContent(file.getBytes())
|
||||
.build();
|
||||
ServerFileUploadResponse response = fileService.upload(fileUploadDto, liteSaasContext);
|
||||
@ -76,10 +84,12 @@ public class WebFileController {
|
||||
if (contextInfo != null) {
|
||||
liteSaasContext = contextInfo.lite();
|
||||
}
|
||||
String filename = file.getOriginalFilename();
|
||||
BizException.error(filename.length() > FILE_NAME_MAX_LENGTH, FILE_NAME_TOO_LONG);
|
||||
ServerFileUploadDto fileUploadDto = ServerFileUploadDto.builder()
|
||||
.appCode(appCode)
|
||||
.bizScene(bizScene)
|
||||
.fileName(file.getOriginalFilename())
|
||||
.fileName(filename)
|
||||
.fileContent(file.getBytes())
|
||||
.build();
|
||||
FileInformationResponse response = fileService.uploadV2(serviceName, fileUploadDto, liteSaasContext);
|
||||
|
||||
@ -41,6 +41,7 @@ public enum CodeEnum implements EnumBase<Integer> {
|
||||
FILE_FORMAT_NOT_SUPPORTED(109,"file format is not supported"),
|
||||
FILE_UPLOAD_FAILED(109,"file upload failed"),
|
||||
MISSING_REQUEST_PARAM(110, "missing request param"),
|
||||
FILE_NAME_TOO_LONG(111, "file name too long max 128"),
|
||||
|
||||
;
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.axzo.oss.http.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
@ -20,6 +21,7 @@ public class ServerFileUploadRequest {
|
||||
@NotBlank(message = "bizScene must not be null")
|
||||
private String bizScene;
|
||||
@NotBlank(message = "fileName must not be null")
|
||||
@Length(max = 128, message = "文件名不能超过128个字符")
|
||||
private String fileName;
|
||||
@NotNull(message = "fileContent must not be null")
|
||||
private byte[] fileContent;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.axzo.oss.http.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
@ -18,6 +19,7 @@ public class ServerFileUploadV2Request {
|
||||
@NotBlank(message = "bizScene must not be null")
|
||||
private String bizScene;
|
||||
@NotBlank(message = "fileName must not be null")
|
||||
@Length(max = 128, message = "文件名不能超过128个字符")
|
||||
private String fileName;
|
||||
@NotBlank(message = "serviceName must not be null")
|
||||
private String serviceName;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user