问题:https://jfinal.com/feedback/8272
中文文件名有毒,快逃,能不用就不要用。下面抛个我的砖,不知道有没有大佬有更好的解法。
前端:(带中文的完整路径url,先URLencode,再base64)
var url ="带中文的完整路径";
window.open("/rest/file/"+window.btoa(encodeURIComponent(url)));后端:先拆base64再URLdecode
@path("/rest/file")
public class FileRest extends BaseRest {
@Clear
public void index() {
String path = getPara();
if (StringUtils.isBlank(path)) {
renderNull();
} else {
path = URLUtil.decode(Base64.decodeStr(path));
File localFile = null;
if (path.startsWith("/userfiles/特定目录免得别人搞事")) {
localFile = new File(PathKit.getWebRootPath() + path);
}
if (localFile != null && localFile.exists()) {
renderFile(localFile);
} else {
renderNull();
}
}
}
}