2017-09-28 27 views
0

我使用CKeditor为我的网站。将图像成功上传到云端之后,我无法获取网址。它说“图片源URL丢失”。我知道如果图像上传属性模式的URL丢失,ckeditor无法显示图像。但我不知道如何获得网址.... 这是我的代码,但不工作。ckeditor,nodejs - 如何获取图像的网址?

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

什么是输出,在格兰当u打印结果的console.log finally块(结果) – user1428716

+0

它没有打印任何东西......但是当我把'console.log代码'放到最后一个bock的第一行时,它成功地打印结果。 – ShutUpILoveYou

+0

显示内部打印的输出最后var htm; .. console.log – user1428716

回答

1

的问题是,你是不是封闭的URL脚本标签中:

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

这应该工作:

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