@At("/addPic")
@POST
@AdaptBy(type = UploadAdaptor.class,args={"${app.root}/WEB-INF/tmp/release", "8192", "utf-8", "20000", "10485760"})
public Object uploadPic(@Param("file") TempFile tf, HttpServletRequest req,AdaptorErrorContext err){
NutMap re=new NutMap();
String msg=null;
String path;
if(err!=null&&err.getAdaptorErr()!=null) {
msg = "文件大小不符合规定";
}else if(tf==null){
msg="空文件";
}else{
try (InputStream ins = tf.getInputStream()) {
BufferedImage image = Images.read(ins);
image = Images.zoomScale(image, 512, 512, Color.WHITE);
String basepath=req.getServletContext().getRealPath("articleImg/release/");
File directory = new File(basepath);
if (!directory.exists()) {
directory.mkdirs();
}
path=R.UU16();
Images.writeJpeg(image, new File(basepath+ path+".jpg"), 0.8f);
} catch(DaoException e) {
e.printStackTrace();
msg = "系统错误";
} catch (Throwable e) {
msg = "图片格式错误";
}
}
if(msg!=null){
return re.setv("ok",false).setv("msg",msg);
}
return re.setv("ok",true).setv("path","sss");
}
上传完文件返回
{
"data": "{\n \"ok\": true,\n \"path\": \"sss\"\n}",
"statusCode": 200,
"errMsg": "uploadFile:ok"
}
想不明白。其他方法也是这样返回,格式是对的,
有什么办法解决吗