6

当我使用“快速上传”选项卡上传文件时,成功上传后 URL 不会传递到“图像信息”选项卡。如果我在上传成功后从“快速上传”中选择“确定”,CKFinder 会切换到“图像信息”选项卡,并出现以下错误消息“图像源 URL 缺失”。谁能阐明为什么会发生这种情况?

4

2 回答 2

1

使用此代码。

在 CKEditor 配置中 -

config.filebrowserUploadUrl = "/VirtualDirectoryName/ControllerName/ActionName";

你的行动方法

public class ControllerName: Controller
    {
        public ActionResult ActionName(HttpPostedFileBase upload, string CKEditorFuncNum, string CKEditor, string langCode)
        {
            if (upload != null)
            {
                string fileName = Guid.NewGuid() + Path.GetExtension(upload.FileName);

                string basePath = Server.MapPath("~/Uploads");
                upload.SaveAs(basePath + "\\" + fileName);

                string url = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath + "/Uploads/" + fileName;

                HttpContext.Response.Write("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + url + "\");</script>");
                HttpContext.Response.End();
            }

            return View();
        }
    }
于 2015-08-20T07:20:12.990 回答
0

它适用于 CKEditor 4。你可以这样尝试:

public ActionResult uploadnow(HttpPostedFileWrapper upload, string CKEditorFuncNum)
    {
        string path = "";
        string pathWeb ="";
        if (upload != null)
        {
            string ImageName = upload.FileName;
            string extention = Path.GetExtension(ImageName);
            string name = DateTime.Now.ToString("yyMMddhhmmssms");
            ImageName = name + extention;
            pathWeb = "/images/uploads/" + ImageName;
            path = System.IO.Path.Combine(Server.MapPath("~/images/uploads"), ImageName);
            upload.SaveAs(path);
            HttpContext.Response.Write("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + pathWeb + "\");</script>");
            HttpContext.Response.End();
        }
        return View();
    }
于 2017-07-01T01:20:31.380 回答