[英]I have a problem with uploading my images with ckeditor
I have tried to upload images with ckeditor but my problem is that the images upload to the server folders but ddoesnt show in my ckeditor text area , it show server response error , any help please ?我曾尝试使用 ckeditor 上传图像,但我的问题是图像上传到服务器文件夹,但在我的 ckeditor 文本区域中没有显示,它显示服务器响应错误,请问有什么帮助吗? This is my code :
这是我的代码:
router.post('/upload&responseType=json', function(req, res) {
var fs = require('fs');
var tmpPath = req.files.upload.name;
l = tmpPath.split('/').length;`enter code here`
var fileName = tmpPath.split('/')[l - 1] + "_" + "s";
var buf = new Buffer.from(req.files["upload"].data);
var newPath ='public/uploads/'+tmpPath;
console.log(newPath);
console.log(tmpPath);
console.log(fileName);
fs.writeFile(newPath,buf, function (err) {
if (err) console.log({err: err});
else {
html = "uploaded";
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);
}
});
});
This is my ckeditor这是我的ckeditor
CKEDITOR.config.customConfig = '/js/ckeditor_config.js';
CKEDITOR.replace(editor2,{ filebrowserUploadUrl: '/upload', });
And this my ckeditor config file :这是我的 ckeditor 配置文件:
CKEDITOR.editorConfig = function( config )
{
config.filebrowserUploadMethod = 'form';
config.toolbar = 'MyToolbar';
config.toolbar_MyToolbar =
[
['Source','Templates'],
['Cut','Copy','Paste','SpellChecker','-','Scayt'],
['Undo','Redo','-','Find','Replace'],
['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
['Maximize','-','About'],
'/',
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','SelectAll','RemoveFormat'],
['Link','Unlink','Anchor'],
['Styles','Format','Font','FontSize'],
['TextColor','BGColor']
];
};
You do not have to send the whole HTML in the newer versions of ckeditor.. You are just supposed to send the URL as shown below:您不必在较新版本的 ckeditor 中发送整个 HTML。您只应该发送如下所示的 URL:
res.send({
url: "<SERVER_URL>/public/uploads/" + fileName,
})
If you are working on localhost replace SERVER_URL with something like http://localhost:3000如果您在 localhost 上工作,请将 SERVER_URL 替换为http://localhost:3000
Another thing, you have to set另一件事,你必须设置
app.use(express.static('public/uploads'));
If you want to access the image using the URL mentioned above.如果您想使用上述 URL 访问图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.