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);
}
}
}
$(
"#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
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
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
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
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?
I'm unable to observe such behavior locally. Here is a short video which captures the sample local behavior.
Greetings,
Rosen
the Telerik team
@(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" })
)
Attached is a screenshot.
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
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
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
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");
}
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.
Rosen
Telerik