CKEditor的使用

1.引入js库

<script src="https://cdn.ckeditor.com/4.6.1/standard-all/ckeditor.js"></script>

2.定义一个textarea标签

<textarea id="editor">
</textarea>

3.用CkEditor替换textarea即可使用基本功能

CKEDITOR.replace('editor');

4.配置CkEditor

添加图片上传,代码插入工具

CKEDITOR.replace('editor-box', {
//GitHub地址:https://github.com/ckeditor
toolbar: [
{ name: 'document', items: ['Source'] },
{ name: 'basicstyles', items: ['Bold', 'Italic'] },
{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote'] },
{ name: 'links', items: ['Link', 'Unlink'] },
{ name: 'insert', items: ['Image','CodeSnippet'] },
{ name: 'styles', items: ['Format', 'Styles'] }
],
filebrowserImageUploadUrl: '/Blogs/UploadImageUrl', //配置图片上传后台Url
customConfig: '',
extraPlugins: 'codesnippet,image2,uploadimage',
removePlugins: 'image',
//mathJaxLib: 'https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-AMS_HTML',
codeSnippet_theme: 'ir_black',
height: 450,
contentsCss: ['https://cdn.ckeditor.com/4.6.1/standard-all/contents.css'],
format_tags: 'p;h1;h2;h3;pre',
removeDialogTabs: 'image:advanced;link:advanced;link:target',
stylesSet: [
/* Inline Styles */
{ name: 'Marker', element: 'span', attributes: { 'class': 'marker' } },
{ name: 'Cited Work', element: 'cite' },
{ name: 'Inline Quotation', element: 'q' },
/* Object Styles */
{
name: 'Special Container',
element: 'div',
styles: {
padding: '5px 10px',
background: '#eee',
border: '1px solid #ccc'
}
},
{
name: 'Compact table',
element: 'table',
attributes: {
cellpadding: '5',
cellspacing: '0',
border: '1',
bordercolor: '#ccc'
},
styles: {
'border-collapse': 'collapse'
}
},
{ name: 'Borderless Table', element: 'table', styles: { 'border-style': 'hidden', 'background-color': '#E6E6FA' } },
{ name: 'Square Bulleted List', element: 'ul', styles: { 'list-style-type': 'square' } },
/* Widget Styles */
{ name: 'Illustration', type: 'widget', widget: 'image', attributes: { 'class': 'image-illustration' } },
{ name: 'Featured snippet', type: 'widget', widget: 'codeSnippet', attributes: { 'class': 'code-featured' } },
{ name: 'Featured formula', type: 'widget', widget: 'mathjax', attributes: { 'class': 'math-featured' } }
]
});

5.后台接收图片

/// <summary>
/// 图片上传
/// </summary>
/// <param name="env"></param>
/// <returns></returns>
public async Task<IActionResult> UploadImageUrl([FromServices]IHostingEnvironment env)
{
// CKEditor提交的很重要的一个参数
string callback = Request.Query["CKEditorFuncNum"];
var form = Request.Form;
var img = form.Files[]; //获取图片
string fileName = img.FileName;
var openReadStream = img.OpenReadStream();
byte[] buff = new byte[openReadStream.Length];
await openReadStream.ReadAsync(buff, , buff.Length);
string filenameGuid = Guid.NewGuid().ToString();
var bowerPath = PathUtils.GetSavePath(filenameGuid, true) + ".jpg";//获取到图片保存的路径,这边根据自己的实现
var savePath = Path.Combine(env.WebRootPath, bowerPath);
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
await fs.WriteAsync(buff, , buff.Length);
//服务器返回JavaScript脚本
string result = $"<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction(\"{callback}\", \"{"/"+bowerPath}\", \"\");</script>";
Response.ContentType = "text/html;charset=UTF-8";
return Content(result);
}
}

6.注意

服务器返回需要加上这个,否则会遇到前端页面不执行返回的JavaScript脚本的问题

Response.ContentType = "text/html;charset=UTF-8";

配置完成即可使用图片上传功能

CKEditor与dotnetcore实现图片上传的更多相关文章

  1. ckeditor+jsp+spring配置图片上传

    CKEditor用于富文本输入是极好的,它还有一些插件支持扩展功能,其中图片上传就是比较常用到的.本文简单记录我的实现步骤. 1.CKEditor除了提供三种标准版压缩包下载,还可根据自己的需求进行个 ...

  2. 富文本编辑器CKeditor的配置和图片上传,看完不后悔

    CKeditor是一款富文本编辑器,本文将用极为简单的方式介绍一下它的使用和困扰大家很久的图片上传问题,要有耐心. 第一步:如何使用 1.官网下载https://ckeditor.com/ckedit ...

  3. django + ckeditor + 七牛云,图片上传到七牛云

    传送门 本人使用的是 Django 的自带的管理后台,安装 ckeditor 富文本编辑器后,上传图片的时候直接传到七牛云的.

  4. .net core CKEditor 图片上传

    最近在玩 asp.net core,不想用UEditor,想使用CKEditor.故需要图片上传功能. 废话不多说,先上效果图: CKEditor 前端代码: <text id="co ...

  5. easyui+webuploader+ckeditor实现插件式多图片上传

    需求:在ckeditor编辑器上实现多图片上传并要求另外单独选择ckeditor上传的图片作为封面 页面效果说明: 动态效果图: 第一步:页面布局 <html xmlns="http: ...

  6. WINDOW.PARENT.CKEDITOR.TOOLS.CALLFUNCTION 图片上传

    CKEDITOR  编辑器   图片上传 WINDOW.PARENT.CKEDITOR.TOOLS.CALLFUNCTION (CKEditorFuncNum,图片路径,返回信息); CKEditor ...

  7. CKEditor实现图片上传

    本人用的CKEditor版本为4.3 CKEditor配置和部署参考CKEditor4.x部署和配置. CKEditor编辑器的工具栏中初始的时候应该是这样子的,没有图片上传按钮 并且预览中有一堆火星 ...

  8. 简单2步实现 asp.net mvc ckeditor 图片上传

    1.打开ckeditor 包下的  config.js,添加一句 配置(PS:ckeditor 很多功能都在该配置文件里配置),如下: config.filebrowserImageUploadUrl ...

  9. CKEditor 自主控制图片上传

    在ASP.NET中使用CKEditor编辑器,如果想控制图片上传,即把上传的图片路径名存到数据中,可以自定义一个上传功能 首先自定义CKEditor的配置文件 在config.js中添加以下代码,红色 ...

随机推荐

  1. VMware Workstation 12 Pro 之安装林耐斯-Elementaryos-系统

    VMware Workstation 12 Pro 之安装林耐斯-Elementaryos-系统... ---------------- ------------------------------- ...

  2. 区别jquery对象和dom对象及转换方法

    一.jquery对象 由$() 获取,例如 var div = $("#id"); 这个div是jquery对象,它里面没有dom对象自带的方法.常见的dom对象自带的方法, 例如 ...

  3. C++读取csv表格文件到vector

    这个CSV文件假设知道每行有多少个数,也知道数据的格式,即可使用下面简单的方法实现. 我们假设每行有4个数据,依次是int,int,float,float 基本思路是:把每行的数据定为一个类型,放在v ...

  4. Druid使用记录

    最近项目稳定下来,就像折腾一下看看系统的运行情况,但是我们搞java的毕竟不是专业运维,看看数据库的运行情况就ok了. 1 Druid介绍 官方地址 https://github.com/alibab ...

  5. 关于RESTful接口api的设计

    你封装api的话,你对同城,你相当于客户端,你只顺应他的签权机制:别人调你的话,你有一套签权机制,别人就是客户端,只顺应你的签权:这样就统一了,容易扩展,以后你接了几套签权,别人对你还是一套,你们就是 ...

  6. [2014-02-19]ConfigurationSection:让web.config配置更有条理

    本文针对新手 使用Web.config的配置信息,一般都习惯于使用 ConfigurationManager.AppSettings["ConfigKey"] 当程序不断迭代,开发 ...

  7. v-cloak 实现vue实例未编译完前不显示

    前言: 由于网速原因,(ps:之前同事无意间在网速很差的情况下测出的)在使用vue开发时,会由于vue实例还没编译成功的时候数据绑定的"Mustache"标签会闪现一下,造成不好的 ...

  8. ctf常见php弱类型分析

    1. 布尔反序列化 $unserialize_str = $_POST['password']; $data_unserialize = unserialize($unserialize_str); ...

  9. 【详细资料】ICN6211:MIPI DSI转RGB芯片简介

    ICN6211功能MIPI DSI转RGB,分辨率1920*1200,封装QFN48

  10. 5.分析内核中断运行过程,以及中断3大结构体:irq_desc、irq_chip、irqaction

    本节目标:    分析在linux中的中断是如何运行的,以及中断3大结构体:irq_desc.irq_chip.irqaction 在裸板程序中(参考stmdb和ldmia详解): 1.按键按下, 2 ...