Browse Source

更新上传图片接口

Administrator 4 years ago
parent
commit
d49e1f7a71

+ 6 - 0
ruoyi-admin/pom.xml

@@ -72,6 +72,12 @@
             <groupId>com.ruoyi</groupId>
             <artifactId>ruoyi-generator</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.jetbrains</groupId>
+            <artifactId>annotations</artifactId>
+            <version>RELEASE</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 7 - 3
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java

@@ -105,13 +105,15 @@ public class FileUploadUtils
         {
             throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
         }
-
+        //校验文件大小校验和后缀名
         assertAllowed(file, allowedExtension);
-
+        //编码文件名
         String fileName = extractFilename(file);
-
+        //根据目录创建文件夹
         File desc = getAbsoluteFile(baseDir, fileName);
+        //上传
         file.transferTo(desc);
+        //组合上传地址
         String pathFileName = getPathFileName(baseDir, fileName);
         return pathFileName;
     }
@@ -167,7 +169,9 @@ public class FileUploadUtils
             throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
         }
 
+        //获取文件原始名称
         String fileName = file.getOriginalFilename();
+        //获取文件名的后缀
         String extension = getExtension(file);
         if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
         {

+ 1 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -113,6 +113,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/webjars/**").anonymous()
                 .antMatchers("/*/api-docs").anonymous()
                 .antMatchers("/druid/**").anonymous()
+                .antMatchers("/common/upload").anonymous()
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()
                 .and()