Unplanned
Last Updated: 02 Feb 2021 07:17 by Steve
Steve
Created on: 02 Feb 2021 07:17
Category: Editor
Type: Bug Report
1
Editor's FileBrowser upload does not update filename from response from the server.

Bug report

When uploading a file through the Editor's FileBrowser, the file's name is not updated with the name coming generated on the server. The file's name is updated in the ImageBrowser using the same server code.

Editor configuration:

$("#editor").kendoEditor({               
                fileBrowser: {
                    schema: {
                        model: {
                            id: "name",
                            fields: {
                                name: { field: "name" },
                                type: { field: "type" },
                                size: { field: "size" }
                            }
                        }
                    },
                    transport: {
                        read: "@Url.HttpRouteUrl("ActionApi", new {controller = "MessageTemplates", action = "Read"})",
                        destroy: "",
                        create: "",
                        uploadUrl: "@Url.HttpRouteUrl("ActionApi", new {action = "UploadMp3", controller = "MessageTemplates" })",
                        fileUrl: function (name) {
                            var url = "/files/" + name + "/";
                            return url;
                        }
                    },

                    fileTypes: "*.mp3, *.pdf"
                },
                tools: ['insertImage', 'insertFile']
});

Controller:

[HttpPost]
        [ActionName("Read")]
        public object Read()
        {
            try
            {
                string path = HttpContext.Current.Request.Params["path"];

                var fullPath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/Files/" + path);

                DirectoryInfo dir = new DirectoryInfo(fullPath);
                var result = dir.GetFiles("*.*").Select(f => new
                {
                    name = f.Name,
                    type = "f",
                    size = (long)0,
                }).ToList();

                return result;
            }
            catch (Exception e)
            {
                return null;
                //throw new HttpException(404, "File Not Found");
            }
        }

        [HttpPost]
        [ActionName("UploadMp3")]
        public HttpResponseMessage UploadMp3()
        {
            var file = HttpContext.Current.Request.Files[0];
            try
            {
                return Request.CreateResponse(HttpStatusCode.Created, new
                {
                    size = file.ContentLength,
                    name = Guid.NewGuid().ToString(),
                    type = "f"
                });
            }
            catch (Exception e)
            {
                return new HttpResponseMessage(HttpStatusCode.BadRequest);
            }
        }

Reproduction of the problem

  1. Open the Editor's FileBrowser.
  2. Upload a file.

Current behavior

The file name is not updated whereas it is being updated in the ImageBrowser.

Expected/desired behavior

The file name should be updated as in the ImageBrowser.

Environment

0 comments