Upload not taking the full path but only the filename in Imagebrowser

2 posts, 0 answers
  1. Shanmuga
    Shanmuga  avatar
    1 posts
    Member since:
    Jul 2012

    Posted 21 Nov 2013 Link to this post

    Hi,

    I am using the image browser to upload  images to  FTP server(we are using Akamai FTP). I have written a process  whereby the file is uploaded,and the MVC controller uploads and saves the image in my FTP specified location with the same name with which is is uploaded as.  It then returns the JSON result with that name of the image. I have checked the sample "KendoEditorImageBrowser" given by your team but  this process is working perfectly on a local machine. However, for FTP server or for other locations the image was uploaded, but the thumbnail keeps on rotating.

    While debugging the code I found that the Thumbnail is getting called with only the file name but not the path with Which I call or  in which the file is located(I have provided the path location in code) which is of no help for me.

    But when I close and reopen my Image Browser the image is getting loaded correctly.  I am using the latest Kendo UI version

    This is my Controller code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.Mvc;
    using MarketingAdvocate.Admin.Controllers.Base;
    using MarketingAdvocate.Admin.Models.CampaignDetail;
    using System.IO;
    using MarketingAdvocate.Utility.Common;
    using System.Web;
    using System.Web.Mvc;
    using System.Net;

    namespace MarketingAdvocate.Admin.Controllers
    {
        public class ImageBrowserController:BaseController
        {
             private const string prettyName = "Images/";        
            private const string DefaultFilter = "*.png,*.gif,*.jpg,*.jpeg";

            private const int ThumbnailHeight = 80;
            private const int ThumbnailWidth = 80;

            private readonly DirectoryBrowser directoryBrowser;
            private readonly ThumbnailCreator thumbnailCreator;

            public ImageBrowserController()
            {
                directoryBrowser = new DirectoryBrowser();
                thumbnailCreator = new ThumbnailCreator();
            }

            /// <summary>
            /// Upload
            /// </summary>
            /// <param name="file"></param>
            /// <returns></returns>
            [AcceptVerbs(HttpVerbs.Post)]
            public virtual ActionResult Upload(string path,HttpPostedFileBase file)
            {

                Utility.Business.Client.Client client = new Utility.Business.Client.Client(ClientId);
                Utility.Business.Client.SiteSection siteSection = new Utility.Business.Client.SiteSection(SiteSectionId);

                Utility.Business.FTPUpload ftpUpload = new Utility.Business.FTPUpload();
                var fullclient = client.ClientId + "_" + client.FolderForAkamai;
                var fullsitesection = siteSection.SiteSectionId + "_" + siteSection.FolderForAkamai;
                var destination = "/Clients/" + fullclient + "/" + fullsitesection + "/" + "Email" + "/" + "Images" + "/" + "Test" + "/";
                var fileLenght = 0;
                if ((string.IsNullOrEmpty(path)) || (path == "/"))
                {
                    path = destination;
                }
                var source = string.Empty;
                Random rnd = new Random();
                var uploadFirstImages = file;
                if (uploadFirstImages != null && uploadFirstImages.ContentLength > 0)
                {
                    source = uploadFirstImages.FileName.Replace("/", "\\");

                    if (source.IndexOf("\\") != -1)
                    {
                        source = source.Substring(source.LastIndexOf("\\") + 1);
                    }

                    while (ftpUpload.FileExist(source, destination))
                    {
                        source = rnd.Next(0, 1000).ToString() + "|" + source;
                    }
                    var fileInputStream = uploadFirstImages.InputStream;
                    ftpUpload.CopyFile(source, fileLenght, fileInputStream, path);

                }

                return Json(new
                {
                    size =  file.ContentLength,
                    name = ""http://url here" + path + file.FileName,
                    type = "f"
                }, "text/plain");

               
            }

            /// <summary>
            /// Read
            /// </summary>
            /// <returns></returns>
            public virtual JsonResult Read(string path)
            {

                Utility.Business.Client.Client client = new Utility.Business.Client.Client(ClientId);
                Utility.Business.Client.SiteSection siteSection = new Utility.Business.Client.SiteSection(SiteSectionId);
                var fullclient = client.ClientId + "_" + client.FolderForAkamai;
                var fullsitesection = siteSection.SiteSectionId + "_" + siteSection.FolderForAkamai;
                var destination = "/Clients/" + fullclient + "/" + fullsitesection + "/" + "Email" + "/" + "Images" + "/" + "Test/";

                if ((string.IsNullOrEmpty(path)) || (path == "/"))
                {
                    path = destination;
                }
                directoryBrowser.Server = Server;

                var result = directoryBrowser
                    .GetContent(path, DefaultFilter)
                    .Select(f => new
                    {
                        name = "http:url here" + path + f.Name,
                        type = f.Type == EntryType.File ? "f" : "d",
                        size = f.Size
                    });

              
                return Json(result, JsonRequestBehavior.AllowGet);

                //return Json(destination);

            }

            [OutputCache(Duration = 3600, VaryByParam = "path")]
            public virtual ActionResult Thumbnail(string path)
            {
                
                return CreateThumbnail(path);

            }

            private FileContentResult CreateThumbnail(string physicalPath)
            {
                WebClient client = new WebClient();
                Stream stream = client.OpenRead(physicalPath);
                using (var fileStream = stream)
                {
                    var desiredSize = new ImageSize
                    {
                        Width = ThumbnailWidth,
                        Height = ThumbnailHeight
                    };

                    const string contentType = "image/png";

                    return File(thumbnailCreator.Create(fileStream, desiredSize, contentType), contentType);
                }
            }

            [AcceptVerbs(HttpVerbs.Post)]
            public virtual ActionResult Create(string path, FileBrowserEntry entry)
            {
                var name = entry.Name;

                Utility.Business.Client.Client client = new Utility.Business.Client.Client(ClientId);
                Utility.Business.Client.SiteSection siteSection = new Utility.Business.Client.SiteSection(SiteSectionId);
                var fullclient = client.ClientId + "_" + client.FolderForAkamai;
                var fullsitesection = siteSection.SiteSectionId + "_" + siteSection.FolderForAkamai;
                var destination = "/Clients/" + fullclient + "/" + fullsitesection + "/" + "Email" + "/" + "Images" + "/" + "Test/";
                Utility.Business.FTPUpload ftpUpload = new Utility.Business.FTPUpload();
                ftpUpload.CreateFTPDirectory(destination);
                return Json(null);
            }

            [OutputCache(Duration = 360, VaryByParam = "path")]
            public ActionResult Image(string path)
            {

                Utility.Business.Client.Client client = new Utility.Business.Client.Client(ClientId);
                Utility.Business.Client.SiteSection siteSection = new Utility.Business.Client.SiteSection(SiteSectionId);
                var fullclient = client.ClientId + "_" + client.FolderForAkamai;
                var fullsitesection = siteSection.SiteSectionId + "_" + siteSection.FolderForAkamai;
                var destination = "/Clients/" + fullclient + "/" + fullsitesection + "/" + "Email" + "/" + "Images" + "/" + "Test/";
                WebClient url = new WebClient();
                var physicalPath = "http://qa.cdn.marketingadvocate.net" + destination + path;
                Stream stream = url.OpenRead(physicalPath);
                //var physicalPath = Server.MapPath(path);

                const string contentType = "image/png";
                return File(stream, contentType);

            }

        }
    }

    This is my view:
     </div>
                    <link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.common.min.css" rel="stylesheet" />
                    <link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.rtl.min.css" rel="stylesheet" />
                    <link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.default.min.css"
                        rel="stylesheet" />
                    <link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.dataviz.min.css"
                        rel="stylesheet" />
                    <link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.dataviz.default.min.css"
                        rel="stylesheet" />
                    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
                    <script src="http://cdn.kendostatic.com/2013.3.1119/js/kendo.all.min.js"></script>
                    <script src="http://cdn.kendostatic.com/2013.3.1119/js/kendo.timezones.min.js"></script>
                    @(Html.Kendo().Editor()
          .Name("editor")
          .HtmlAttributes(new { style = "width: 585px;height:400px" })
          .Tools(tools => tools
              .Clear()
              .Bold().Italic().Underline().Strikethrough()
              .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull()
              .InsertUnorderedList().InsertOrderedList()
              .Outdent().Indent()
              .CreateLink().Unlink()
              .InsertImage()
              .SubScript()
              .SuperScript()
              .TableEditing()
              .ViewHtml()
              .Formatting()
              .FontName()
              .FontSize()
              .FontColor().BackColor()

          )

          .Value(@<text>
                    </text>)
    .ImageBrowser(ImageBrowser => ImageBrowser
         .Upload("Upload", "ImageBrowser")
    .Read("Read", "ImageBrowser")
    .Create("Create", "ImageBrowser")
    .Thumbnail("Thumbnail", "ImageBrowser")
         )


    )


    Thanks
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 25 Nov 2013 Link to this post

    Hi Shanmuga,

    I covered this question in the support ticket on the same topic. Please take a look at it.

    I wish you a great day!

    Regards,
    Dimiter Madjarov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top