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。。两种方案
 
一、手动设置
res.type('html');

在res.json
二、直接调用send 方法
result.state='SUCCESS';res.send(JSON.stringify(result))

相关文章
相关标签/搜索