ssm使用ueditor自定义上传图片时图片插进数据库了但是不能回显在编辑器上,编辑器提示上传错误,
这是我jsp压面添加js自定义上传路径
但是我返回的json数据是对的,这是我的后台代码
public Map uploadFile(@RequestParam(value = "upfile", required = false) MultipartFile file,
HttpServletRequest request,HttpServletResponse response) throws IOException{
response.setContentType("text/html;charset=UTF-8");
Map map = new HashMap();
String originalFilename = file.getOriginalFilename();
String name = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
// 获取上传图片的扩展名(jpg/png/...)
String extension = FilenameUtils.getExtension(originalFilename);
// 图片上传的相对路径(因为相对路径放到页面上就可以显示图片)
String path = "/image/" + name + "." + extension;
String uuidname = name+"."+extension;
// 图片上传的绝对路径
String url = request.getSession().getServletContext().getRealPath("") + path;
InputStream in = file.getInputStream();
File dir = new File(url);
OutputStream out = new FileOutputStream(dir);
byte bs[] = new byte[in.available()];
in.read(bs);
out.write(bs);
out.flush();
out.close();
in.close();
Image image = new Image();
image.setImageTitle(originalFilename);
image.setUrl(path);
boolean b = articleImageServiceDao.insertArticleImage_01(image);
if(b){
map.put("state", "SUCCESS");// UEDITOR的规则:不为SUCCESS则显示state的内容
map.put("url",path); //能访问到你现在图片的路径
map.put("title","");
map.put("original",originalFilename);
}else{
map.put("state", "文件上传失败!"); //在此处写上错误提示信息,这样当错误的时候就会显示此信息
map.put("url","");
map.put("title", "");
map.put("original", "");
}
return map;
这是我的config.json
uc浏览器上传时提示错误和json返回数据