ShutUpILoveYou
ShutUpILoveYou

Reputation: 446

ckeditor,nodejs - how to get the image url?

I use CKeditor for my website. After uploading an image into cloudinary successfully, i failed to get URL on . It says "image source URL is missing". I know if URL on image uploading attribute modal was missing, ckeditor can't show me the image. but i don't know how to get the url.... this is my code but not work.

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);
    });

});

Upvotes: 0

Views: 860

Answers (1)

ncardeli
ncardeli

Reputation: 3492

The problem is that you are not enclosing the url inside the script tag:

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

This should work:

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

Upvotes: 1

Related Questions