nodejs ueditor图片上传功能

406 阅读1分钟

最近更新博文,使用ueditor上传图片的时候报了错误,ueditor 后端配置项没有正常加载,上传插件不能正常使用!做了一下研究,总结了使用的方法,具体操作步骤如下:

1.在ueditor文件夹下,更新ueditor.config.js中设置服务器统一请求接口路径:

   serverUrl: URL + "ue"

2.在项目app.js文件中,添加:

//使用模块  

app.use("/libs/ueditor/ue", ueditor(path.join(__dirname, 'app/public'), function (req, res, next) {  

    // ueditor 客户发起上传图片请求  

    if (req.query.action === 'uploadimage') {

        var foo = req.ueditor;  

  

        var imgname = req.ueditor.filename;  

  

        var img_url = '/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 = '/images/ueditor/';  

        res.ue_list(dir_url); // 客户端会列出 dir_url 目录下的所有图片  

    }  

    // 客户端发起其它请求  

    else {  

        // console.log('config.json')  

        res.setHeader('Content-Type', 'application/json');  

        res.redirect('/libs/ueditor/jsp/config.json');  

    }  

})); 

3.更新ueditor/jsp文件夹下config.json中图片访问路径前缀:

   

"imageUrlPrefix": "frontendlife.cn"

\