无关风月
2026-01-17 4a4d2741c5962dc0e5d7101b3435c2ab8312ff8a
ruoyi-common/src/main/java/com/ruoyi/common/core/controller/FileController.java
@@ -39,7 +39,8 @@
        }
        String TimeDir =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
//        String realPath = fileUploadConfig.getLocation() + TimeDir;
        String realPath = "D:\\upload\\image\\" + TimeDir;
//        String realPath = "D:\\upload\\image\\" + TimeDir;
        String realPath = "F:\\file\\strainLibrary\\" + TimeDir;
        File file = new File(realPath);
        // 没有目录就创建
        if (!file.exists()) {
@@ -47,19 +48,26 @@
        }
        // 获取文件名称
        String filename = mf.getOriginalFilename();
        // 生成随机5位英文字母
        String rename = "";
        for (int i = 0; i < 5; i++) {
            rename += (char) (Math.random() * 26 + 'a');
        }
        long l = System.currentTimeMillis();
        // 获取文件后缀
        String ext = filename.substring(filename.lastIndexOf("."), filename.length());
        String temp = rename+l+filename;
        String ext = temp.substring(temp.lastIndexOf("."), temp.length());
        // 检查文件类型
        if (!fileUploadConfig.getAllowExt().contains(ext)) {
            return AjaxResult.error("上传文件格式不正确,仅支持" + fileUploadConfig.getAllowExt());
        }
        File targetFile = new File(realPath, filename);//目标文件
        File targetFile = new File(realPath, temp);//目标文件
        //开始从源文件拷贝到目标文件
        //传图片一步到位
        mf.transferTo(targetFile);
        //拼接数据
//        String imgstr = fileUploadConfig.getAccessPath() + TimeDir +"\\"+ filename;
        String imgstr = TimeDir +"/"+ filename;
        String imgstr = TimeDir +"/"+ temp;
        return AjaxResult.success(imgstr);
    }
@@ -92,7 +100,7 @@
            return "请传入文件!";
        }
        String TimeDir =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        String realPath = "D:\\upload\\image" + TimeDir;
        String realPath = "F:\\file\\strainLibrary\\" + TimeDir;
        File file = new File(realPath);
        // 没有目录就创建
        if (!file.exists()) {