[英]CkEditor Is not uploading images and files. Even i have no Option to upload image or files
[英]I have a problem with uploading my images with ckeditor
我曾嘗試使用 ckeditor 上傳圖像,但我的問題是圖像上傳到服務器文件夾,但在我的 ckeditor 文本區域中沒有顯示,它顯示服務器響應錯誤,請問有什么幫助嗎? 這是我的代碼:
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);
}
});
});
這是我的ckeditor
CKEDITOR.config.customConfig = '/js/ckeditor_config.js';
CKEDITOR.replace(editor2,{ filebrowserUploadUrl: '/upload', });
這是我的 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']
];
};
您不必在較新版本的 ckeditor 中發送整個 HTML。您只應該發送如下所示的 URL:
res.send({
url: "<SERVER_URL>/public/uploads/" + fileName,
})
如果您在 localhost 上工作,請將 SERVER_URL 替換為http://localhost:3000
另一件事,你必須設置
app.use(express.static('public/uploads'));
如果您想使用上述 URL 訪問圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.