NutzCN Logo
问答 Nutz没有权限创建文件池
发布于 2354天前 作者 jadendong 1580 次浏览 复制 上一个帖子 下一个帖子
标签:

在实践NutzBook 这个项目时,做到上传头像的入口方法。出现没有权限创建文件夹。
我在项目中WEB-INF对应的地方创建好了,没用。
求职

 @AdaptBy(type = UploadAdaptor.class, args = {"${app.root}/WEB-INF/tmp/user_avatar", "8192", "utf-8", "20000", "102400"})
 @POST
 @Ok(">>:/user/profile")
 @At("/avatar")
 public void uploadAvatar(@Param("file") TempFile tf, @Attr(scope = Scope.SESSION, value = "me") int userId, AdaptorErrorContext err) {
 String msg = null;
 if (err != null && err.getAdaptorErr() != null) {
 msg = "文件大小不符合规定";
 } else if (tf == null) {
 msg = "空文件";
 } else {
 UserProfile profile = get(userId);
 try {
 BufferedImage image = Images.read(tf.getFile());
 image = Images.zoomScale(image, 128, 128, Color.WHITE);
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 Images.writeJpeg(image, out, 0.8f);
 profile.setAvatar(out.toByteArray());
 dao.update(profile, "^avatar$");
 } catch (DaoException e) {
 log.info("System Error", e);
 msg = "系统错误";
 } catch (Throwable e) {
 msg = "图片格式错误";
 }
 }

    if (msg != null)
        Mvcs.getHttpSession().setAttribute("upload-error-msg",msg);
}
2018-06-06 10:11:32,799 org.nutz.filepool.NutFilePool.(NutFilePool.java:25) INFO - Init file-pool by: D:/apps/Tomcat8/webapps/ROOT/WEB-INF/tmp/user_avatar", "8192", "utf-8", "20000", "102400 [2000]
2018-06-06 10:11:32,803 org.nutz.lang.Files.createDirIfNoExists(Files.java:423) WARN - create filepool dir(D:\apps\Tomcat8\webapps\ROOT\WEB-INF\tmp\user_avatar", "8192", "utf-8", "20000", "102400) fail!!
2018-06-06 10:11:32,805 org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:51) DEBUG - Eval FAIL!! : public void com.jaden.nutzbook.module.UserProfileModule.uploadAvatar(org.nutz.mvc.upload.TempFile,int,org.nutz.mvc.impl.AdaptorErrorContext)
org.nutz.lang.born.BorningException: Fail to born or cast to 'org.nutz.mvc.upload.UploadAdaptor'
 by args: [@(D:/apps/Tomcat8/webapps/ROOT/WEB-INF/tmp/user_avatar", "8192", "utf-8", "20000", "102400)]
 because:java.lang.RuntimeException: 'D:/apps/Tomcat8/webapps/ROOT/WEB-INF/tmp/user_avatar", "8192", "utf-8", "20000", "102400' should be a directory or don't have permission to create it!
 at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:25)
 at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
 at org.nutz.lang.Mirror.born(Mirror.java:1010)
 at org.nutz.mvc.impl.Loadings.evalObj(Loadings.java:336)
 at org.nutz.mvc.impl.processor.AbstractProcessor.evalObj(AbstractProcessor.java:48)
 at org.nutz.mvc.impl.processor.AdaptorProcessor.evalHttpAdaptor(AdaptorProcessor.java:34)
 at org.nutz.mvc.impl.processor.AdaptorProcessor.init(AdaptorProcessor.java:20)
 at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:38)
 at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:54)
 at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:205)
 at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:108)
 at org.nutz.mvc.ActionHandler.(ActionHandler.java:19)
8 回复

求助,求职写错惹~~

贴子为什么没有删除功能,我上一条发了个一个的贴。单没有高亮,就重发一遍

D:/apps/Tomcat8/webapps/ROOT/WEB-INF/tmp/user_avatar 是个文件? 或者 D:/apps/Tomcat8/webapps/ROOT/WEB-INF/tmp是个文件?

都是文件夹

改成 ${app.root}/abc 试试

解决了,谢谢。
原因是"${app.root}/WEB-INF/tmp/user_avatar", "8192", "utf-8", "20000", "102400"}
我复制的,IDEA 自动加了转移符,变成这样"8192"。

\
我粘贴时又转回去了,所以你看不到

添加回复
请先登陆
回到顶部