Contribute to this guideReport an issue

guideGetting started

If you would like to go straight to the point and see an example of an application with working CKFinder, have a look at the CKFinder 3 for Java - demo application repository.

# 1. Add CKSource Maven Repository to your project

Gradle

// build.gradle
repositories {
    mavenCentral()
    maven {
        url = 'https://maven.cksource.com/'
    }
}

Maven

<!-- pom.xml -->
<repository>
    <id>cksource-mvn-repo</id>
    <name>CKSource Maven Repository</name>
    <url>https://maven.cksource.com/</url>
</repository>

# 2. Add CKFinder in project dependencies

Gradle

// build.gradle
dependencies {
    compile 'com.cksource:ckfinder3:3.5.1'
}

Maven

<!-- pom.xml -->
<dependency>
    <groupId>com.cksource</groupId>
    <artifactId>ckfinder3</artifactId>
    <version>3.5.1</version>
</dependency>

# 3. Enable the CKFinder servlet in your configuration

<!-- web.xml -->
<servlet>
    <servlet-name>CKFinder</servlet-name>
    <servlet-class>com.cksource.ckfinder.servlet.CKFinderServlet</servlet-class>
    <multipart-config>
        <location>/tmp</location>
        <max-file-size>5242880</max-file-size><!--5MB-->
        <max-request-size>20971520</max-request-size><!--20MB-->
        <file-size-threshold>0</file-size-threshold>
    </multipart-config>
</servlet>

Please note that the multipart configuration is mandatory. File uploads in CKFinder will not work without it.

The above example assumes that the servlet is registered in the web.xml file, but you might want to register it another way. Here you can read more about servlet registration methods.

# 4. Add the configuration file and adjust the configuration options

At this point you need to alter the configuration options to configure paths used by CKFinder, define access permissions, file extension whitelists, etc.

By default, the CKFinder connector looks for a configuration file named ckfinder.yml in application resources. Here you can find a template of this configuration file.

If you would like to load the configuration from any other location, have a look at the Loading configuration from a custom location tutorial.

In case when the files managed by CKFinder are served through the web server, it is recommended to perform some server configuration fine-tuning to make sure the files are served in a secure manner. To read more, refer to the Securing a publicly accessible folder article.

# 5. Configure authentication

Usually, you will want to restrict the access to CKFinder, so only authenticated users of your application can upload or browse files. You can achieve this by implementing a custom Authenticator.

To read more, refer to the Configuring authentication tutorial.

# Demo application

Check an example of a basic setup of CKFinder in a Spring Boot application.

Please note that Spring Boot is not necessary to use CKFinder, you can set it up like any other regular servlet. If you would like to read more about servlet registration methods, refer to the How to Register a Servlet in Java article by Baeldung.