This is a migrated thread and some comments may be shown as answers.

Implementing Image Browser for editor

15 Answers 1302 Views
Editor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Shaun Mitchem
Top achievements
Rank 1
Shaun Mitchem asked on 04 Dec 2012, 12:41 PM
Hi there

I am trying to implement Image Browser for Kendo Editor using the example here : http://demos.kendoui.com/web/editor/imagebrowser.html

My controller class : 

public class ImageBrowserController : EditorImageBrowserController
    {
        private const string contentFolderRoot = "~/Content/";
        private const string prettyName = "Images/";
        private static readonly string[] foldersToCopy = new[] { "~/uploads/newsitem/" };
 
 
        /// <summary>
        /// Gets the base paths from which content will be served.
        /// </summary>
        public override string ContentPath
        {
            get
            {
                return CreateUserFolder();
            }
        }
 
        private string CreateUserFolder()
        {
            var virtualPath = Path.Combine(contentFolderRoot, "UserFiles", prettyName);
 
            var path = Server.MapPath(virtualPath);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                foreach (var sourceFolder in foldersToCopy)
                {
                    CopyFolder(Server.MapPath(sourceFolder), path);
                }
            }
            return virtualPath;
        }
 
        private void CopyFolder(string source, string destination)
        {
            if (!Directory.Exists(destination))
            {
                Directory.CreateDirectory(destination);
            }
 
            foreach (var file in Directory.EnumerateFiles(source))
            {
                var dest = Path.Combine(destination, Path.GetFileName(file));
                System.IO.File.Copy(file, dest);
            }
 
            foreach (var folder in Directory.EnumerateDirectories(source))
            {
                var dest = Path.Combine(destination, Path.GetFileName(folder));
                CopyFolder(folder, dest);
            }
        }
    }
My js code

$("#Content").kendoEditor({
        encoded: false,
        imageBrowser: {
            messages: {
                dropFilesHere: "Drop files here"
            },
            transport: {
                read: "/console/ImageBrowser/Read",
                destroy: {
                    url: "/console/ImageBrowser/Destroy",
                    type: "POST"
                },
                create: {
                    url: "/console/ImageBrowser/Create",
                    type: "POST"
                },
                thumbnailUrl: "/console/ImageBrowser/Thumbnail",
                uploadUrl: "/console/ImageBrowser/Upload",
                imageUrl: "/console/ImageBrowser/Image?path={0}"
            }
        },
        tools: [
            "bold",
            "italic",
            "underline",
            "strikethrough",
            "fontSize",
            "foreColor",
            "backColor",
            "justifyLeft",
            "justifyCenter",
            "justifyRight",
            "justifyFull",
            "createLink",
            "unlink",
            "insertImage",
            "style",
            "viewHtml"
        ],
        style: [
                { text: "Highlight Error", value: "hlError" },
                { text: "Highlight OK", value: "hlOK" },
                { text: "Inline Code", value: "inlineCode" }
        ],
        stylesheets: [
            "../../content/web/editor/editorStyles.css"
        ]
    });

My image folder is : /uploads/newsitem and the code generates a folder /content/userfiles/images and this folder does have write permission. 

When any actions are invoked on EditorImageBrowserController they are 404'ed. I've attached a screen shot to show what is going on.

Any help would be greatly appreciated.

15 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 06 Dec 2012, 07:36 AM
Hello Shaun,

I suspect that the behavior you are experiencing is caused by the fact that the server-side code you are using is for the Editor for KendoUI for ASP.NET MVC widget wrapper. Thus, you may consider using the wrapper instead, or maybe implement the server logic required by the ImageBrowser.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Shaun Mitchem
Top achievements
Rank 1
answered on 10 Dec 2012, 01:11 PM
Hi there

Thanks for your reply - I actually just lifted the code from your Kendo example : 

http://demos.kendoui.com/web/editor/imagebrowser.html 

In that case, do you have an up-to-date example/implementation ?

Thanks
0
Rosen
Telerik team
answered on 11 Dec 2012, 07:53 AM
Hi Shaun,

The code in question is up-to-date, however as I have mentioned, it is specific to the KendoUI for ASP.NET MVC wrapper of the Editor widget. Thus, will not work as it is with the plain KendoUI Editor. However, you can find attached an example which shows how to use the  KendoUI Web Editor widget within ASP.NET MVC.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Shaun Mitchem
Top achievements
Rank 1
answered on 14 Dec 2012, 02:46 PM
That's fantastic - thank you !
0
George
Top achievements
Rank 1
answered on 04 Mar 2013, 04:44 PM
I am trying to integrate the same...

Firstly - great example, all the uploads worked perfectly, and the folder creation and navigation - However the selection and insertion of the actual images doesn't work?

All I did was download the example, KendoEditorImageBrowser.zip, and ran it... all worked correctly except when you click an image in the image browser, nothing happens...

[EDIT]

It seems to be in chrome that this happens, just tried it in FF and works fine. - maybe just a chrome issue?
0
Rosen
Telerik team
answered on 05 Mar 2013, 07:39 AM
Hello George,

I'm unable to observe such behavior locally. Here is a short video which captures the sample local behavior.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Georgi
Top achievements
Rank 2
answered on 01 Aug 2013, 04:39 PM
The example project works great, but when I try to use it with the mvc wrapper looking like this:

@(Html.Kendo().EditorFor(x => x.HtmlContent)
               .Tools(tools =>
               {
                   tools.ViewHtml();
                   tools.InsertImage();
                   tools.Styles(styles =>
                       {
                           styles.Add("Image left 300px", "image-left-300");
                           styles.Add("Text left", "text-left");
                           styles.Add("Text padding", "text-padding");
                       });
               })
               .StyleSheets(styleSheets =>
                   {
                       styleSheets.Add(Url.Content("~/Content/css/EditorStyles.css"));
                   })
               .ImageBrowser(imageBrowser => imageBrowser
                   .Image("~/UserFiles/Images/Uploaded/{0}")
                   .Read("Read", "ImageBrowser")
                   .Create("Create", "ImageBrowser")
                   .Destroy("Destroy", "ImageBrowser")
                   .Upload("Upload", "ImageBrowser")
                   .Thumbnail("Thumbnail", "ImageBrowser"))
               .HtmlAttributes(new { style = "width: 100%; height: 400px" })
           )
Uploading & Selecting works great, but when I close the image browser and open it up again I get the uploaded files detected as directories with 'undefined' names.

Attached is a screenshot.
0
Rosen
Telerik team
answered on 02 Aug 2013, 02:05 PM
Hello Georgi,

The project attached in my previous reply is intended to be used with the plain KendoUI Editor. A version applicable for KendoUI for ASP.NET MVC can be found in the sample application available with the KendoUI for ASP.NET MVC distribution.

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Georgi
Top achievements
Rank 2
answered on 02 Aug 2013, 07:04 PM
I tested the example, but it seems incomplete. When I upload an image I see 'undefined' for a file name and the image does not display until I reopen the image browser. The image is uploaded correctly however and it is displayed after reopen.
0
Rosen
Telerik team
answered on 05 Aug 2013, 10:18 AM
Hi Georgi,

The described issue is a known one and the fix should be available in the next internal build. Therefore, please download it and give it a try.

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
claudio
Top achievements
Rank 1
answered on 26 Oct 2013, 01:33 AM
Any update in this bug?
0
Rosen
Telerik team
answered on 28 Oct 2013, 07:33 AM
Hello claudio,

The fix for the mentioned issue is available in the latest (Q2 2013 SP1) official release of KendoUI. Did you try it?

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
claudio
Top achievements
Rank 1
answered on 28 Oct 2013, 02:17 PM
I'm using the Q2 2013 SP1 2013.2.918 version, have the seme problem that in the 2013.2.716, after upload an image in image browser the thumbnail dont show and says undefinied, but after reload the image is show correctly. Also if i change the folder and come back to the original folder where it was uploaded.
0
claudio
Top achievements
Rank 1
answered on 28 Oct 2013, 02:20 PM
I get my code from one of your examples, this is from my ImageBrowserController for Upload and Thumbnail. im connecting an sqlserver 2012 DB

 public ActionResult Thumbnail(string path)
        {
            //TODO:Add security checks

            var files = new FilesRepository();
            var image = files.ImageByPath(path);
            if (image != null)
            {
                var desiredSize = new ImageSize { Width = ThumbnailWidth, Height = ThumbnailHeight };

                const string contentType = "image/png";

                var thumbnailCreator = new ThumbnailCreator(new FitImageResizer());

                using (var stream = new MemoryStream(image.Image1.ToArray()))
                {
                    return File(thumbnailCreator.Create(stream, desiredSize, contentType), contentType);
                }
            }
            throw new HttpException(404, "File Not Found");
        }

 public ActionResult Upload(string path, HttpPostedFileBase file)
        {
            if (file != null)
            {
                var files = new FilesRepository();
                var parentFolder = files.GetFolderByPath(path);
                if (parentFolder != null)
                {
                    files.SaveImage(parentFolder, file);
                    return Json(
                        new
                        {
                            name = Path.GetFileName(file.FileName)
                        }
                    , "text/plain");
                }
            }
            throw new HttpException(404, "File Not Found");
        }
0
Rosen
Telerik team
answered on 28 Oct 2013, 03:06 PM
Hello claudio,

Are you using the KendoUI for ASP.NET MVC or KendoUI Web. The code you have pasted seems to be correct if the KendoUI Web is used and will not work in case of ASP.NET MVC wrappers. This is due to the fact that casing of the returned data is not valid for ASP.NET MVC wrappers schema definition. 

On a side note I would ask you to open a separate support request if additional questions arise, in which to state the exact version you are using and provide more detailed information about your scenario.

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Editor
Asked by
Shaun Mitchem
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Shaun Mitchem
Top achievements
Rank 1
George
Top achievements
Rank 1
Georgi
Top achievements
Rank 2
claudio
Top achievements
Rank 1
Share this question
or