Ver código fonte

综合展示修改为原始文件名

wangyangyang 4 anos atrás
pai
commit
1a8f335bce

+ 41 - 0
sms_water/src/main/java/com/huaxu/common/FileUploadUtil.java

@@ -44,6 +44,22 @@ public class FileUploadUtil {
             throw new IOException(e.getMessage(), e);
         }
     }
+    /**
+     * 根据文件路径上传
+     *
+     * @param baseDir 相对应用的基目录
+     * @param file    上传的文件
+     * @return 文件名称
+     * @throws IOException
+     */
+    public static final String uploadWeb2(String baseDir, MultipartFile file) throws IOException {
+        try {
+            return uploadForOrginalFilename(baseDir, file, MimeType.DEFAULT_ALLOWED_EXTENSION);
+        } catch (Exception e) {
+            throw new IOException(e.getMessage(), e);
+        }
+    }
+
 
     /**
      * 获取文件名的后缀
@@ -159,4 +175,29 @@ public class FileUploadUtil {
         String pathFileName = getPathFileName(baseDir, fileName);
         return pathFileName;
     }
+
+
+    /**
+     * 文件上传
+     *
+     * @param baseDir 相对应用的基目录
+     * @param file    上传的文件
+     * @return 返回上传成功的文件名
+     * @throws IOException 比如读写文件出错时
+     */
+    public static final String uploadForOrginalFilename(String baseDir, MultipartFile file, String[] allowedExtension) throws RxcException, IOException, InvalidExtensionException {
+        int fileNamelength = file.getOriginalFilename().length();
+        if (fileNamelength > FileUploadUtil.DEFAULT_FILE_NAME_LENGTH) {
+            throw new RxcException("10004", "文件太大");
+        }
+
+        assertAllowed(file, allowedExtension);
+
+        String fileName = file.getOriginalFilename();//extractFilename(file);
+
+        File desc = getAbsoluteFile(baseDir, fileName);
+        file.transferTo(desc);
+        String pathFileName = getPathFileName(baseDir, fileName);
+        return pathFileName;
+    }
 }

+ 1 - 1
sms_water/src/main/java/com/huaxu/controller/ComdisplayMapController.java

@@ -46,7 +46,7 @@ public class ComdisplayMapController{
         String avatar = "";
         if (!file.isEmpty()) {
             try {
-                avatar = FileUploadUtil.uploadWeb(baseDir, file);
+                avatar = FileUploadUtil.uploadWeb2(baseDir, file);
             } catch (IOException e) {
                 return new AjaxMessage<>(ResultStatus.ERROR, e.getMessage());
             }