@At("/file")
@AdaptBy(type = UploadAdaptor.class, args = { "ioc:imageUpload" })
@POST
@Ok("json")
public String uploadPhoto(@Param("upfile") TempFile tf,
HttpServletRequest req) {
Map<String, Object> map = new HashMap<>();
try {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String p = Globals.AppRoot;
String f = Globals.AppUploadPath+ "/image/"+ df.format(new Date())+ "/"+ tf.getSubmittedFileName().substring(
tf.getSubmittedFileName().indexOf("."));
Files.write(new File(p + f), tf.getInputStream());
map.put("result", "上传成功!");
} catch (Exception e) {
map.put("result", "上传失败!");
} catch (Throwable e) {
map.put("result", "上传失败!");
}
return Json.toJson(map);
}
7 回复
添加回复
请先登陆