zoukankan      html  css  js  c++  java
  • nodejs对接ueditor编辑器图片上传问题

    这里 用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 对应接口

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

  • 相关阅读:
    [HEOI2013]Segment
    决策单调性胡扯笔记
    HDU 4352 XHXJ's LIS
    WC前计划做但一定会鸽的事情
    LGP5667 拉格朗日插值2
    BZOJ3516 国王奇遇记加强版
    ### Paper about Event Detection
    ### GIT
    ###《Max-Margin Early Event Detectors》
    ### matlab
  • 原文地址:https://www.cnblogs.com/lllomh/p/14991860.html
Copyright © 2011-2022 走看看