这里 用use 因为请求有 get 也有 post  所以不能固定指定方式

 

const path=require('path');
//加载ueditor 模块
var ueditor = require("ueditor");

router.use("/ueditor/ue", ueditor(path.join(__dirname, '/'), function (req, res, next) {
  // ueditor 客户发起上传图片请求
  if (req.query.action === 'uploadimage') {
    var foo = req.ueditor;

    var imgname = req.ueditor.filename;

    var img_url = '../public/images/ueditor/';
    res.ue_up(img_url); //你只要输入要保存的地址 。保存操作交给ueditor来做
    res.setHeader('Content-Type', 'text/html');//IE8下载需要设置返回头尾text/html 不然json返回文件会被直接下载打开

  }
  // 客户端发起图片列表请求
  else if (req.query.action === 'listimage') {
    var dir_url = '../public/images/ueditor/';

    res.ue_list(dir_url); // 客户端会列出 dir_url 目录下的所有图片
  }
  // 客户端发起其它请求
  else {
    // console.log('config.json')
    res.setHeader('Content-Type', 'application/json');
    res.redirect('/ueditor/nodejs/config.json');
  }
}));

对应保存在这个目录

 

前端ued config.js 对应接口

 

返回的地址没有域名导致图片没法访问  在 后台 包加上 

posted on 2021-05-11 18:21  lllomh  阅读(92)  评论(0编辑  收藏  举报