Kristin C
Kristin C

Reputation: 53

CKFinder - The uploaded file is corrupt

I am trying to use CKFinder in my .NET application. I cannot get any uploads to work, no matter how big or small the file is, or what type of file it is. I have given everyone entire control over the folder that CKFinder should be uploading to (for testing purposes), and it still doesn't work. It is always giving me a "The uploaded file is corrupt" error. Doesn't matter if I try to run it local on my Windows 7 machine, or if I push live on a Windows Server 2012 R2 machine. Please someone help...there is no documentation about this, or I cannot find anything that is relevant to this situation. Thank you in advance!

Upvotes: 1

Views: 1336

Answers (2)

kfazi
kfazi

Reputation: 617

It is possible Friendly URLs are responsible for your issue.

If you are using WebForms on .NET Framework 4 (or newer) make sure requests to CKFinder are not modified by WebFormsFriendlyUrlResolver.

You can do this by disabling friendly URLs altogether or by adding your own implementation of WebFormsFriendlyUrlResolver to EnableFriendlyUrls method (usually done in RouteConfig class).

A custom implementation of WebFormsFriendlyUrlResolver may look like this:

public class CKFinderWebFormsFriendlyUrlResolver : WebFormsFriendlyUrlResolver
{
    public override string ConvertToFriendlyUrl(string path)
    {
        if (!string.IsNullOrEmpty(path) && path.ToLower().Contains("/editor/ckfinder"))
        {
            return path;
        }

        return base.ConvertToFriendlyUrl(path);
    }
}

Upvotes: 6

Kristin C
Kristin C

Reputation: 53

Figured it out in VB.NET. Here is the code. Hoping it helps someone else someday!

    Public Class MyWebFormsFriendlyUrlResolver
    Inherits WebFormsFriendlyUrlResolver

    Public Sub New()

        MyBase.New()

    End Sub

    Public Overrides Function ConvertToFriendlyUrl(path As String) As String

        If Not String.IsNullOrEmpty(path) And path.ToLower.Contains("/ckfinder") Then

            Return path

        End If

        Return MyBase.ConvertToFriendlyUrl(path)

    End Function

End Class

Public Class RouteConfig

    Public Shared Sub RegisterRoutes(routes As RouteCollection)

        routes.MapPageRoute("P", "P", "~/P.aspx")            

        Dim settings As FriendlyUrlSettings = New FriendlyUrlSettings()
        settings.AutoRedirectMode = RedirectMode.Permanent

        routes.EnableFriendlyUrls(settings, New Microsoft.AspNet.FriendlyUrls.Resolvers.IFriendlyUrlResolver() {New MyWebFormsFriendlyUrlResolver()})

    End Sub

End Class

Upvotes: 4

Related Questions