Prechádzať zdrojové kódy

文件名称长度校验

郎学彬 3 rokov pred
rodič
commit
c38c18ce0c

+ 13 - 0
sc-service/src/main/java/com/huyi/service/common/file/FileController.java

@@ -34,6 +34,10 @@ public class FileController extends BaseController
     private TokenService tokenService;
     @Autowired
     private RemoteFileService remoteFileService;
+    /**
+     * 默认的文件名最大长度 70
+     */
+    public static final int DEFAULT_FILE_NAME_LENGTH = 60;
 
     /**
      * 永久接口存储
@@ -44,6 +48,9 @@ public class FileController extends BaseController
     {
         if (!file.isEmpty())
         {
+            if(file.getOriginalFilename().length()>DEFAULT_FILE_NAME_LENGTH){
+                return AjaxResult.error("文件名称太长,建议长度小于"+DEFAULT_FILE_NAME_LENGTH);
+            }
             LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
             String companyId = loginUser.getSysUser().getCompanyId();
             //获取token
@@ -80,6 +87,9 @@ public class FileController extends BaseController
     {
         if (!file.isEmpty())
         {
+            if(file.getOriginalFilename().length()>DEFAULT_FILE_NAME_LENGTH){
+                return AjaxResult.error("文件名称太长,建议长度小于"+DEFAULT_FILE_NAME_LENGTH);
+            }
             LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
             String companyId = loginUser.getSysUser().getCompanyId();
             //获取token
@@ -107,6 +117,9 @@ public class FileController extends BaseController
     {
         if (!file.isEmpty())
         {
+            if(file.getOriginalFilename().length()>DEFAULT_FILE_NAME_LENGTH){
+                return AjaxResult.error("文件名称太长,建议长度小于"+DEFAULT_FILE_NAME_LENGTH);
+            }
             LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
             R<SysFile> fileResult = remoteFileService.upload(file,"01");
             if (StringUtils.isNull(fileResult) || StringUtils.isNull(fileResult.getData()))