【问题标题】:ckeditor,nodejs - how to get the image url?ckeditor,nodejs - 如何获取图像网址?
【发布时间】:2017-09-29 05:19:15
【问题描述】:

我在我的网站上使用 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);
    });

});

【问题讨论】:

  • 当你打印结果console.log(result)时,最终阻塞的输出是什么
  • 它什么也没打印...但是当我将'console.log code'放入finally bock的第一行时,它会成功打印结果。
  • 显示最终打印在里面的输出 var htm;..console.log
  • var html 没有被复制...

标签: javascript node.js ckeditor


【解决方案1】:

问题是您没有将 url 包含在脚本标签内:

    html += " var url = " + result.url;

这应该可行:

    html += " var url = '" + result.url + "'";

【讨论】:

    猜你喜欢
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    • 1970-01-01
    相关资源
    最近更新 更多