jfinal 2.2 和3.0 getFile() 底层 MultipartRequest 类 反馈问题

 调用代码 :  getFile("parm", "E:/resources/", 3*1024*1024);

执行到 MultipartRequest  类中class getFinalPath方法。uploadPath 值为"E:/resources/",

if (uploadPath.startsWith("/") || uploadPath.startsWith("\\"))  进不去! 

\\  是不是应该改为: 号啊?  


private String getFinalPath(String uploadPath) {

if (uploadPath == null) {

throw new IllegalArgumentException("uploadPath can not be null.");

}

uploadPath = uploadPath.trim();

if (uploadPath.startsWith("/") || uploadPath.startsWith("\\")) {

if (baseUploadPath.equals("/")) {

return uploadPath;

} else {

return baseUploadPath + uploadPath;

}

} else {

return baseUploadPath + File.separator + uploadPath;

}

}


导致无法上传! 

Directory E:\upload\E:/resources/ not exists and can not create directory.



评论区

JFinal

2017-02-21 11:27

jfinal 后期的版本,引入了一个叫 baseUploadPath 的概念,该变量值可以通过 me.setBaseUploadPath(...) 进行配置,然后所有上传文件都会以这个 baseUploadPath 为基础路径去存放,在 getFile("parm", "E:/resources/", 3*1024*1024); 中指定的 "e:/reources/" 只会当成为一个相对路径

具体到方案,可以通过 me.setBaseUploadPath("E:/resources/") 配置一下就好

如果你的项目有所谓的多个 baseUploadPath 存在,可以用一下 File 移动目录来实现

JFinal

2017-02-21 11:29

使用 baseUploadPath 的好处是,可以很方便地转移整个上传目录到其它的某个目录,例如原先是在 C:/files 目录,发现 C 盘空间不够了,需要转移到 D:/new_path,则只需要改下 baseUploadPath

如果没有固定一个 baseUploadPath 值,要做以上的改变会非常麻烦,很可能需要改 java 代码

热门反馈

扫码入社