E1ED922C1E9526DD63272D7EC5C6CB77
2021-01-04 f5387362c822af8e5c584a2e002d23d12b0fd1f3
添加通用文件上传
1个文件已修改
46 ■■■■■ 已修改文件
src/main/java/com/hx/util/FileUtils.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/util/FileUtils.java
@@ -369,6 +369,52 @@
    }
    /**
     * 文件上传
     * @param platformIconFile
     * @param unifiedFolder
     * @param saveFolder
     * @param autoDateFolder
     * @return
     */
    public static String handleOtherFileUpload(MultipartFile platformIconFile,String unifiedFolder,String saveFolder
            ,boolean autoDateFolder) {
        String fileName = "";
        try {
            if(platformIconFile == null) {
                throw new TipsException("请上传文件!");
            }
            if(autoDateFolder){
                if(saveFolder.endsWith("/")){
                    saveFolder = saveFolder+dateFormat(new Date(),"yyyyMM")+"/";
                }else{
                    saveFolder = saveFolder+"/"+dateFormat(new Date(),"yyyyMM")+"/";
                }
            }
            fileName = dateFormat(new Date(),"yyyyMMddHHmmssSSS");
            if(unifiedFolder.endsWith("/")){
                if(saveFolder.startsWith("/")){
                    saveFolder = saveFolder.replaceFirst("/","");
                    unifiedFolder  = unifiedFolder + saveFolder;
                }else{
                    unifiedFolder  = unifiedFolder+saveFolder;
                }
            }else{
                if(saveFolder.startsWith("/")){
                    unifiedFolder  = unifiedFolder + saveFolder;
                }else{
                    unifiedFolder  = unifiedFolder+"/"+saveFolder;
                }
            }
            fileName = saveFolder+fileUp(platformIconFile,unifiedFolder,fileName);
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return fileName;
    }
    /**
     * 2020-06-29 ChenJiaHe
     * @param file             //文件对象
     * @param filePath        //上传路径