我在我的网站上使用CKeditor。成功将图像上传到cloudinary后,我无法获取URL。它说"图像源URL丢失"。我知道如果图像上传属性模式上的URL丢失了,ckeditor就无法显示图像。但我不知道如何获得网址.... 这是我的代码,但不起作用。
router.post('/uploadImage',multipartMiddleware,(req,res,next)=>{
console.log(req.files);
let imageFile = req.files.upload.path;
cloudinary.uploader.upload(imageFile,
{
tags: 'photobook',
folder: req.body.category + '/',
public_id: req.files.upload.originalFilename
})
.then(function (result) {
console.log('Picture uploaded to Cloudinary');
// Check the image Json file
console.log(result);
// Save photo with image metadata
})
.then(function (result) {
console.log('Successfully saved');
// Remove image from local folder
var filePath = req.files.upload.path;
fs.unlinkSync(filePath);
//////-----------it works successfully here ------------////////
})
.finally(function (result) {
console.log('this log is well shown up');
var html;
html = "";
html += "<script type='text/javascript'>";
html += " var funcNum = " + req.query.CKEditorFuncNum + ";";
html += " var url = " + result.url;
html += " var message = \"upload successfully\";";
html += " window.parent.CKEDITOR.tools.callFunction(funcNum, url);";
html += "</script>";
console.log("it doesn't show up"); //really doesn't show up
// Show the result with image file
res.send(html);
});
});
答案 0 :(得分:1)
问题是您没有将url包含在脚本标记内:
html += " var url = " + result.url;
这应该有效:
html += " var url = '" + result.url + "'";