-
-
Save RedactedProfile/ac48c270d2bbe739f9f3 to your computer and use it in GitHub Desktop.
| var express = require('express'); | |
| var router = express.Router(); | |
| var multipart = require('connect-multiparty'); | |
| var multipartMiddleware = multipart(); | |
| router.get('/', function(req, res) { | |
| res.render('index'); | |
| }); | |
| router.post('/uploader', multipartMiddleware, function(req, res) { | |
| var fs = require('fs'); | |
| fs.readFile(req.files.upload.path, function (err, data) { | |
| var newPath = __dirname + '/../public/uploads/' + req.files.upload.name; | |
| fs.writeFile(newPath, data, function (err) { | |
| if (err) console.log({err: err}); | |
| else { | |
| html = ""; | |
| html += "<script type='text/javascript'>"; | |
| html += " var funcNum = " + req.query.CKEditorFuncNum + ";"; | |
| html += " var url = \"/uploads/" + req.files.upload.name + "\";"; | |
| html += " var message = \"Uploaded file successfully\";"; | |
| html += ""; | |
| html += " window.parent.CKEDITOR.tools.callFunction(funcNum, url, message);"; | |
| html += "</script>"; | |
| res.send(html); | |
| } | |
| }); | |
| }); | |
| }); | |
| module.exports = router; |
| doctype html | |
| body | |
| form | |
| textarea#ckeditor(name="content") | |
| script. | |
| CKEDITOR.replace('ckeditor', { | |
| filebrowserUploadUrl: '/uploader' | |
| }); | |
req.query.CKEditorFuncNum it will return undefined in every case how can i solve this problem for ckeditor full package
please use ckeditor 4.6
cdn link : https://cdn.ckeditor.com/4.6.0/standard/ckeditor.js
if you use 4.11 version
you will get error when backend response javascript code.
I have looked for a fully working demo, to guide me step by step but I have failed. I even checked the ckeditor documentation for image upload but I am not understanding anything. Can someone help me with a detailed step to step approach to this problem with clear explanation, or is there a link that I can follow. Thanks
I always get an error not found (404) with folder uploader in two cases: set static path and not athough i create folder in root or in public folder. Why?
I always get an error not found (404) with folder uploader in two cases: set static path and not athough i create folder in root or in public folder. Why?
Use a dot(.) after +' sign. Like this: __dirname + './../public/uploads/' + req.files.upload.name;
It will save uploaded image to public/uploads So make a directory name uploads inside public directory first.
Thank you for sharing!