@ApiOperation(value = "上传图片", notes = "上传图片", httpMethod="POST" ,consumes="application/json")
@ApiImplicitParams({
@ApiImplicitParam(name = "Filedata", paramType="query", value = "临时文件", dataType="file", required = true),
})
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:imageUpload"})
@POST
@At
@Ok("json")
//AdaptorErrorContext必须是最后一个参数
public Object image(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
try {
if (err != null && err.getAdaptorErr() != null) {
return Result.error(1,"upload.notvalid");
} else if (tf == null) {
return Result.error("upload.empty");
} else {
String p = Globals.AppRoot;
String f = Globals.AppUploadPath + "/image/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
Files.write(new File(p + f), tf.getInputStream());
return Result.success("upload.success", Globals.AppBase+f);
}
} catch (Exception e) {
return Result.error();
} catch (Throwable e) {
return Result.error("upload.formaterror");
}
}
4 回复
添加回复
请先登陆