Kindeditorの公式Webサイトは、ASP、ASP.NET、およびJSPに関連する統合アプリケーションを提供しています。 http://kindetor.net/docs/upload.htmlは、nodejsの統合を参照して、実用的なnodejsがより簡単であることがわかります
環境:
Unbuntu 14.10
nodejs 0.10.35
Express 4.11.2
恐ろしい1.0.16
Kindeditor 4.1.10
ウェブストーム8
1. IDEまたはターミナルを介してテストという名前のプロジェクトを作成します
2。Package.jsonを編集して、ここで使用される恐ろしい依存関係を追加します。バージョン1.0.16、次に端末を介してNPMインストールを実行して、依存関係のインストールを完了します。
3. Kindeditorのディレクトリ全体をテスト/public/libに入れます
4. index.ejsとindex.jsファイルを変更します
index.ejsにKindeditorを統合します:
KindeditorのuploadjsonをRoute URLに設定して、nodejsが提供する画像アップロードを処理します。これは /uploadimgです
index.jsで画像アップロードを処理するルートURLを追加します:
/uploadimgに対応する後処理方法を追加します。
コードは次のとおりです。
index.js
コードコピーは次のとおりです。
<!doctype html>
<html>
<head>
<title> <%= title%> </title>
<link rel = 'styleSheet' href = '/styleSheets/style.css'/>
<Script charset = "utf-8" src = "/lib/dinkeditor-4.1.10/dinkeditor.js"> </script>
<script charset = "utf-8" src = "/lib/dinkeditor-4.1.10/lang/zh_cn.js"> </script>
<スクリプト>
var options = {
uploadjson: '/uploadimg'
};
Kindeditor.Ready(function(k){
window.editor = k.create( '#editor'、options);
});
</script>
</head>
<body>
<h1> <%= title%> </h1>
<textarea id = "editor" name = "content">
<strong> HTMLコンテンツ</strong>
</textarea>
</body>
</html>
index.js
コードコピーは次のとおりです。
var Express = require( 'Express');
var router = express.router();
var defidable = require( 'Fromidable');
/*ホームページを取得します。 */
router.get( '/'、function(req、res、next){
Res.Render( 'index'、{title: 'image upload'});
});
router.post( '/uploadimg'、function(req、res、next){
var form = new fordidable.incomingform();
form.keepextensions = true;
form.uploaddir = __dirname + '/../public/upload';
form.parse(req、function(err、fields、files){
if(err){
エラーを投げます。
}
var image = files.imgfile;
var path = image.path;
path = path.replace( '//// g'、 '/');
var url = '/upload' + path.substr(path.lastindexof( '/')、path.length);
var info = {
「エラー」:0
「URL」:URL
};
res.send(info);
});
});
module.exports = router;
次に、IDEまたは端子を介してテストプロジェクトを開始し、http:// localhost:3000を介してページにアクセスして画像をアップロードします