yijiusmile
2021-04-20 096f6025e0212b23df8485b56818c3f0b019aa26
febs-common/febs-common-core/src/main/java/cc/mrbird/febs/common/core/utils/MyUtil.java
@@ -117,9 +117,9 @@
        //原本名字
        String fileName = file.getOriginalFilename();
        String suffix = "";
        if (fileName.indexOf(".") > 0) {
        if (fileName.lastIndexOf(".") > 0) {
            //后缀
            suffix = fileName.substring(fileName.indexOf("."), fileName.length());
            suffix = fileName.substring(fileName.lastIndexOf("."));
        }
        //生成新的名字
        String newName = nextIdStr + suffix;
@@ -128,6 +128,35 @@
        return Dict.create().set("fileName",fileName).set("suffix",suffix).set("newName",newName);
    }
    public static Dict filesUpload(MultipartFile file, String uploadPpath) throws FebsException, IOException {
        if (file.isEmpty()) {
            throw new FebsException("上传的文件不能为空!请重新上传");
        }
        if (file.getSize() <= 0) {
            throw new FebsException("上传的文件大小需要大于0kb");
        }
        if (file.getSize() > 200 * 1024* 1024) {
            throw new FebsException("上传的文件大于200M");
        }
        if (!FileUtil.exist(uploadPpath)) {
            FileUtil.mkdir(uploadPpath);
        }
        //原本名字
        String fileName = file.getOriginalFilename();
        String suffix = "";
        if (fileName.lastIndexOf(".") > 0) {
            //后缀
            suffix = fileName.substring(fileName.lastIndexOf("."));
        }
        if(FileUtil.exist(uploadPpath + fileName)){
            throw  new FebsException("文件已经存在");
        }
        //上传
        file.transferTo(new File(uploadPpath + fileName));
        return Dict.create().set("fileName",fileName).set("suffix",suffix);
    }
    /**
     *      对字节数组字符串进行Base64解码并生成图片
      */