Ver Fonte

修复文件上传获取后缀名失败问题

woody há 2 anos atrás
pai
commit
efe2b415ef

+ 2 - 1
src/main/java/com/chelvc/cloud/maintain/controller/FileController.java

@@ -5,6 +5,7 @@ import java.io.InputStream;
 
 import com.chelvc.framework.base.annotation.UnifiedResponseBody;
 import com.chelvc.framework.base.util.FileUtils;
+import com.chelvc.framework.base.util.StringUtils;
 import com.chelvc.framework.upload.UploadHandler;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -36,7 +37,7 @@ public class FileController {
      */
     @PostMapping("/file")
     public String upload(@RequestParam("file") MultipartFile file) throws IOException {
-        String suffix = FileUtils.getSuffix(file.getName());
+        String suffix = StringUtils.ifEmpty(file.getOriginalFilename(), FileUtils::getSuffix);
         try (InputStream stream = file.getInputStream()) {
             return this.uploadHandler.upload(stream, suffix);
         }