zoukankan      html  css  js  c++  java
  • expressjs 支持umeditor 的图片上传

    umedtor 的文件上传 是form 提交。
    请求的header
    Accept:
    text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
     
    在dialogs 里面的image.js
                    $('<iframe name="up"  style="display: none"></iframe>').insertBefore(me.dialog).on('load', function(){
                        var r = this.contentWindow.document.body.innerHTML;
                        if(r == '')return;
                        me.uploadComplete(r);
                        $(this).unbind('load');
                        $(this).remove();
     
                    });
    表明返回的是html。so,我们要在express 返回制定的header Content-Type 必须是html
    PS:umeditor 这样做事兼容IE9以下的浏览器,如果不是Content-Type html. form 表单提交就变成下载文件了。
     
     
    在expressjs 中
    res.json 方法如果没有设置,默认设置Content-Type=‘application/json’;
    最后还是调用send 方法
    源码如下
    if (!this.get('Content-Type')) {
    this.set('Content-Type', 'application/json');
    }

    return this.send(body);
    这个不是我们想要的response header。。两种方案
     
    1、手动设置
    res.type('html');
    
    
    在res.json
    2、直接调用send 方法
    result.state='SUCCESS';
    res.send(JSON.stringify(result))
  • 相关阅读:
    Abp Swagger API中文说明配置方法
    ABP框架中使用MySQL数据库
    windows + jenkins + .net core + iis自动化部署新手入门
    在图片上画矩形框
    base64转换成np、opencv、PIL
    RankSVM
    tf.placeholde函数解释与用法
    slim.arg_scope()的使用
    SSD网络结构
    tensorflow学习笔记
  • 原文地址:https://www.cnblogs.com/yoable/p/6370190.html
Copyright © 2011-2022 走看看