Kindeditor Official online provides asp,asp.net,jsp related integration applications, http://kindeditor.net/docs/upload.html can be referenced to achieve NODEJS integration, found that practical nodejs simpler
Environment:
Unbuntu 14.10
Nodejs 0.10.35
Express 4.11.2
Formidable 1.0.16
Kindeditor 4.1.10
Webstorm 8
1. Create a project called Test through the IDE or the terminal
2. Edit Package.json Add formidable dependencies, here is a 1.0.16 version, after which the NPM install completes the dependent installation via the terminal
3. Place Kindeditor entire catalogue under Test/public/lib
4. Modification of Index.ejs and index.js documents
Integrated Kindeditor in Index.ejs:
Set Kindeditor Uploadjson for Nodejs the route URL that is provided for processing picture upload here's the/uploadimg.
Index.js to add a route URL to handle picture uploads:
Add/uploadimg the corresponding post processing method,
The code is as follows:
Index.js
Copy Code code as follows:
<! DOCTYPE html>
<title><%= title%></title>
<link rel= ' stylesheet ' href= '/stylesheets/style.css '/>
<script charset= "Utf-8" src= "/lib/kindeditor-4.1.10/kindeditor.js" ></script>
<script charset= "Utf-8" src= "/lib/kindeditor-4.1.10/lang/zh_cn.js" ></script>
<script>
var options = {
Uploadjson: '/uploadimg '
};
Kindeditor.ready (function (K) {
Window.editor = k.create (' #editor ', options);
});
</script>
<body>
<textarea id= "editor" name= "Content" style= "width:700px;height:300px;" >
<strong>html content </strong>
</textarea>
</body>
Index.js
Copy Code code as follows:
var express = require (' Express ');
var router = Express. Router ();
var formidable = require (' formidable ');
/* Get home page. */
Router.get ('/', function (req, res, next) {
Res.render (' index ', {title: ' Picture Upload '});
});
Router.post ('/uploadimg ', function (req, res, next) {
var form = new Formidable. Incomingform ();
Form.keepextensions = true;
Form.uploaddir = __dirname + '/... /public/upload ';
Form.parse (req, Function (Err, fields, files) {
if (err) {
throw err;
}
var image = Files.imgfile;
var path = Image.path;
Path = Path.replace ('/\\/g ', '/');
var url = '/upload ' + path.substr (path.lastindexof ('/'), path.length);
var info = {
"Error": 0,
"url": URL
};
Res.send (info);
});
});
Module.exports = router;
Then start the test project through the IDE or the terminal, and you can upload the picture through the http://localhost:3000 access page.