Kindeditor의 공식 웹 사이트는 ASP, ASP.NET 및 JSP와 관련된 통합 응용 프로그램을 제공합니다. http://kinditor.net/docs/upload.html은 nodejs의 통합을 참조 할 수 있으며 실제 nodejs가 더 간단하다는 것을 알 수 있습니다.
환경:
Unbuntu 14.10
nodejs 0.10.35
Express 4.11.2
강력한 1.0.16
KindeDitor 4.1.10
Webstorm 8
1. IDE 또는 터미널을 통해 테스트라는 프로젝트 생성
2. Package.json 편집하기 위해 여기에 사용되는 강력한 종속성을 추가하십시오. 버전 1.0.16을 한 다음 터미널을 통해 NPM 설치를 실행하여 종속성 설치를 완료하십시오.
3. Kindeditor의 전체 디렉토리를 Test/Public/Lib에 넣으십시오
4. index.ejs 및 index.js 파일을 수정합니다
index.ejs의 KindeDitor 통합 :
Nodejs에서 제공 한 이미지 업로드를 처리하기 위해 Kindeditor의 UploadJson을 Route URL로 설정하십시오. 다음은 /uploadimg입니다
index.js에서 이미지 업로드를 처리하려면 경로 URL을 추가하십시오.
/uploadImg에 해당하는 게시물 처리 방법을 추가하십시오.
코드는 다음과 같습니다.
index.js
코드 사본은 다음과 같습니다.
<! doctype html>
<html>
<헤드>
<title> < %= Title %> </title>
<link rel = '스타일 시트'href = '/Stylesheets/Style.css'/>
<script charset = "utf-8"src = "/lib/kindeditor-4.1.10/sindeditor.js"> </script>
<script charset = "utf-8"src = "/lib/kindeditor-4.1.10/lang/zh_cn.js"> </script>
<cript>
var 옵션 = {
uploadjson : '/uploadimg'
};
Kindeditor.ready (function (k) {
window.editor = k.create ( '#editor', 옵션);
});
</스크립트>
</head>
<body>
<h1> < %= 제목 %> </h1>
<textArea id = "editor"name = "content">
<strong> HTML 컨텐츠 </strong>
</textarea>
</body>
</html>
index.js
코드 사본은 다음과 같습니다.
var express = 요구 사항 ( 'Express');
var router = express.router ();
var commidable = require ( 'formidable');
/* 홈페이지에 가십시오. */
router.get ( '/', function (req, res, next) {
res.render ( 'index', {title : 'image upload'});
});
router.post ( '/uploadimg', function (req, res, next) {
var form = new commidable.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 (정보);
});
});
module.exports = 라우터;
그런 다음 IDE 또는 터미널을 통해 테스트 프로젝트를 시작하고 http : // localhost : 3000을 통해 페이지에 액세스하려면 사진을 업로드하십시오.