Getting 400 and 415 errors on Destroy

1 Answer 912 Views
FileManager
Randy
Top achievements
Rank 1
Randy asked on 16 Aug 2021, 02:03 AM | edited on 16 Aug 2021, 06:47 PM

I am using the FileManager in ASP.net CORE 5 using the Tag Helpers.  I created a partial view for the FileManager and created a controller to handle the Read, Upload, Destroy, Create.... Currently the read and upload functions work as expected, but when I try to delete a file I Am getting 415 Error using this Tag:

<destroy url="/FileManagerData/Destroy" type="POST"  />

Here is the response:

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"00-cd48a67e3165574bb55f025789ec2570-d50282d662ca804c-00"}

After some research the it appears the 415 and Unsupported Media Type is caused by not passing in the Content Type, so I changed the Tag to this:

<destroy url="/FileManagerData/Destroy" type="POST" content-type="multipart/form-data" />

This produced a 400 error with a response of:

{"errors":{"":["Failed to read the request form. Missing content-type boundary."]},"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-c95edcb44f53ca4aa80654e8ac3f4d6b-80784c169952f14a-00"}

According to you docs the content-type is application/x-www-form-urlencoded which gives me the 415 error.

 

Here is the Destroy Method from the Controller:

 

[HttpPost("Destroy")]
        public virtual ActionResult Destroy(FileManagerEntry entry)
        {
            var path = NormalizePath(entry.Path);


            if (!string.IsNullOrEmpty(path))
            {
                if (entry.IsDirectory)
                {
                    DeleteDirectory(path);
                }
                else
                {
                    DeleteFile(path);
                }

                return new JsonResult(new object[0]);
            }
            throw new Exception("File Not Found");
        }

 

What am I missing here to get this to work?

 

[UPDATE]

 

I Change the Destroy Method in the controller to this:

 public virtual ActionResult Destroy([FromForm] FileManagerEntry entry)

Added [FromForm] Which now produces the following validation errors:

 

{"errors":{"Created":["The value 'Mon Aug 16 2021 10:06:38 GMT-0500 (Colombia Standard Time)' is not valid for Created."],"Modified":["The value 'Mon Aug 16 2021 10:06:38 GMT-0500 (Colombia Standard Time)' is not valid for Modified."],"CreatedUtc":["The value 'Mon Aug 16 2021 10:06:38 GMT-0500 (Colombia Standard Time)' is not valid for CreatedUtc."],"ModifiedUtc":["The value 'Mon Aug 16 2021 10:06:38 GMT-0500 (Colombia Standard Time)' is not valid for ModifiedUtc."]},"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-5bc6f05eed3360458a9c5f37a37c8f11-27e6c765b081e642-00"}

[UPDATE 1]

I Created my own Model to replace the FileManagerEntry but set all the DateTime Fields to Strings:

       

public class FileDataJTE
    {

        public string Name { get; set; }
        public string Path { get; set; }
        public string Extension { get; set; }
        public bool IsDirectory { get; set; }
        public bool HasDirectories { get; set; }
        public string Created { get; set; }
        public string CreatedUtc { get; set; }
        public string Modified { get; set; }
        public string ModifiedUtc { get; set; }


    }

Then I Had to pass that in to the Method and convert and string ie Create, back to DateTime:

[HttpPost("Destroy")]
        public virtual ActionResult Destroy([FromForm] FileDataJTE entry)
        {
            string timeZone;

            if (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Now))
            {

                timeZone = TimeZoneInfo.Local.DaylightName;

            }
            else
            {

                timeZone = TimeZoneInfo.Local.StandardName;

            }

            var created = DateTime.ParseExact(entry.Created, "ddd MMM dd yyyy HH:mm:ss 'GMT'K '(" + timeZone + ")'", CultureInfo.InvariantCulture);

 

Why does this not work with the FileManagerEntry on a Controller?

Any ideas on this or am I even on the right track to get this working?

Thanks

 

--R

 

1 Answer, 1 is accepted

Sort by
0
Patrick | Technical Support Engineer, Senior
Telerik team
answered on 18 Aug 2021, 08:54 PM

Hi Randy,

Upon taking a look at the current thread, it is not apparent the reasoning for the 400 and 415.  However, as a comparison, we have a Razor Page demo with Tag Helpers which may help with comparing the current web application with. 

Here is an item being deleted within the Kendo UI FileManager using that Razor Page Demo:

I hope the Razor Page example helps clarify how to configure the Destroy operation in your Kendo UI FileManager.

Regards,
Patrick
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
FileManager
Asked by
Randy
Top achievements
Rank 1
Answers by
Patrick | Technical Support Engineer, Senior
Telerik team
Share this question
or