不知道是不是我自己的问题。。。代码如下
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:imageUpload"})
@POST
@At("/uploadImage/?")
@Ok("json")
@RequiresPermissions("wx.material.image.add")
//AdaptorErrorContext必须是最后一个参数
@SLog(tag = "上传图片", msg = "图片名称:${args[1].meta.fileLocalPath}")
public Object uploadImage(String wxid, @Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
try {
if (err != null && err.getAdaptorErr() != null) {
return NutMap.NEW().addv("code", 1).addv("msg", "文件不合法");
} else if (tf == null) {
return Result.error("空文件");
} else {
WxApi2 wxApi2 = wxConfigService.getWxApi2(wxid);
WxResp resp = wxApi2.add_material("image", tf.getFile());
if (resp.errcode() != 0) {
return Result.error(resp.errmsg());
}
通过跟踪请求发现,如果没有权限,去冲定向了
Request URL:http://127.0.0.1:8080/nutzwk/private/wx/image/uploadImage/5d66443f8bd94f3db9e84b6aa5798ac2
Request Method:POST
Status Code:302 Found
Remote Address:127.0.0.1:8080
Response Headers
view source
Content-Length:0
Date:Fri, 26 Aug 2016 09:46:46 GMT
Location:http://127.0.0.1:8080/nutzwk/private/login
Server:Jetty(9.2.17.v20160517)
X-Powered-By:nutz/1.r.58-SNAPSHOT <nutzam.com>
而不是返回
{"code":1,"msg":"没有权限"}