Last active
December 19, 2015 15:58
-
-
Save mikekunze/5980077 to your computer and use it in GitHub Desktop.
Simple uploader Express route for CKEditor's Image Upload feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn = function(req, res) { | |
var dest, fileName, fs, l, tmpPath; | |
fs = require('fs'); | |
tmpPath = req.files.upload.path; | |
l = tmpPath.split('/').length; | |
fileName = tmpPath.split('/')[l - 1] + "_" + req.files.upload.name; | |
dest = __dirname + "/public/uploads/" + fileName; | |
fs.readFile(req.files.upload.path, function(err, data) { | |
if (err) { | |
console.log(err); | |
return; | |
} | |
fs.writeFile(dest, data, function(err) { | |
var html; | |
if (err) { | |
console.log(err); | |
return; | |
} | |
html = ""; | |
html += "<script type='text/javascript'>"; | |
html += " var funcNum = " + req.query.CKEditorFuncNum + ";"; | |
html += " var url = \"/uploads/" + fileName + "\";"; | |
html += " var message = \"Uploaded file successfully\";"; | |
html += ""; | |
html += " window.parent.CKEDITOR.tools.callFunction(funcNum, url, message);"; | |
html += "</script>"; | |
res.send(html); | |
}); | |
}); | |
}; | |
export.modules = fn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much for sharing this. I've been struggling with getting the image2 widget to call window.parent.CKEDITOR.tools.callFunction from my Express route. Sending the html string back was key.