CKFinder commands behave just like controllers. They wrap the logic required to handle a request and produce an appropriate response (in CKFinder usually a JSON). Commands are resolved based on the command
URL parameter.
Each command must implement the ICommand interface.
Dependencies are injected into the constructor when the command is needed.
The heart of each command class is its ExecuteAsync method where all the processing occurs.
Executing each of CKFinder commands requires appropriate permissions set in ACL configuration settings. Permissions required by a command may be verified with the IRequestAcl interface:
All existing CKFinder commands can be altered using the events system (for example to add additional information or to change the default JSON response). Please refer to the Events article for more detailed information.
In some cases it may be useful to alter the command parameters passed from CKFinder to the server-side connector. For an example how to do that, please check the AlterCommand plugin in the CKFinder 3 Sample JavaScript Plugins repository.
Custom CKFinder commands can be injected into the connector. Refer to the Custom Commands section of the HOWTO for more information.
It may also be useful to have a look at the ImageInfo plugin in the CKFinder 3 Sample JavaScript Plugins repository to check out how to request commands from a JavaScript plugin. You can find more information in the Sending Command to the Server section of the CKFinder 3 JavaScript Documentation.
Name | Description |
---|---|
command | The name of the command to execute. |
type | The resource type name. |
currentFolder | The current working folder path. |
Description | Copies files from selected folders. |
Method | POST |
Sample request | Copy two files from the Example of the request["files"] = [
{
"name": "file1.jpg",
"type": "Files",
"folder": "/sub1/"
"options": ""
},
{
"name": "file2.png",
"type": "Files",
"folder": "/sub1/"
"options": ""
}
]
/ckfinder/connector?command=CopyFiles&type=Images¤tFolder=/
|
Sample response | {
"resourceType": "Files",
"currentFolder": {
"path": "/",
"url": "/ckfinder/userfiles/images/",
"acl": 255
},
"copied": 2
}
|
Notes | The request should contain an array parameter named files with elements defining source files to be copied. Each array element should contain the following parameters:
|
Description | Creates a child folder. |
Method | POST |
Sample request | Create the /ckfinder/connector?command=CreateFolder&type=Files¤tFolder=/&newFolderName=My Folder
|
Sample response | {
"resourceType": "Files",
"currentFolder": {
"path": "/",
"url": "/ckfinder/userfiles/files/",
"acl": 255
},
"newFolder": "My Folder",
"created": 1
}
|
Description | Deletes given files. |
Method | POST |
Sample request | Delete two files from the Example of the request["files"] = [
{
"name": "file1.jpg",
"type": "Files",
"folder": "/sub1/"
},
{
"name": "file2.png",
"type": "Files",
"folder": "/sub1/"
}
]
/ckfinder/connector?command=DeleteFiles&type=Files¤tFolder=/
|
Sample response | {
"resourceType": "Files",
"currentFolder": {
"path": "/",
"url": "/ckfinder/userfiles/files/",
"acl": 255
},
"deleted": 2
}
|
Notes | The request should contain an array parameter named files with elements defining source files to be deleted. Each array element should contain the following parameters:
|
Description | Deletes a given folder. |
Method | POST |
Sample request | Delete the /ckfinder/connector?command=DeleteFolder&type=Files¤tFolder=/sub1/
|
Sample response | {
"resourceType": "Files",
"currentFolder": {
"path": "/sub1/",
"url": "/ckfinder/userfiles/files/sub1/",
"acl": 255
},
"deleted": 1
}
|
Description | Downloads a file from the server. |
Method | GET |
Sample request | Download the file named /ckfinder/connector?command=DownloadFile&type=Files¤tFolder=/&fileName=Test.jpg
|
Notes | This command does not expect the connector to return a text response. Instead, it must stream the file data to the client. |
Description | Uploads a file to a given folder. |
Method | POST |
Sample request | Upload a file to the root ( /ckfinder/connector?command=FileUpload&type=Files¤tFolder=/
|
Sample response |
{
"resourceType": "Files",
"currentFolder": {
"path": "/",
"url": "/ckfinder/userfiles/files/",
"acl": 255
},
"fileName": "fileName.jpg",
"uploaded": 1
}
|
Notes |
|
Description | Returns the list of files for a given folder. |
Method | GET |
Sample request | Get the list of files inside the /Docs/ folder of the Images resource type: /ckfinder/connector?command=GetFiles&type=Images¤tFolder=/Docs/
|
Sample response | {
"resourceType": "Images",
"currentFolder": {
"path": "/Docs/",
"url": "/ckfinder/userfiles/images/Docs/",
"acl": 255
},
"files": [
{
"name": "image1.png",
"date": "201406080924",
"size": 1
},
{
"name": "測試.png",
"date": "201406080924",
"size": 12
}
]
}
|
Notes | File names may contain non-ASCII characters, like in the example above with Chinese characters. The
The |
Description | Returns a direct URL to a file. |
Method | GET |
Sample request | Get a direct URL to a file named longcat.jpg stored in the /kittens/ folder of the Images resource type: /ckfinder/connector?command=GetFileUrl&type=Images¤tFolder=/kittens/&fileName=longcat.jpg
|
Sample response | {
"resourceType": "Images",
"currentFolder": {
"path": "/kittens/",
"url": "/ckfinder/userfiles/images/kittens/",
"acl": 255
},
"url": "/ckfinder/userfiles/images/kittens/longcat.jpg"
}
|
Notes | The URL returned by this command depends on the backend defined for a resource type. In most cases it is required to define a baseUrl for a backend to be able to obtain valid direct URLs to files. |
Description | Returns the list of child folders for a given folder. |
Method | GET |
Sample request | Get child folders inside the /Docs/ folder of the Images resource type. /ckfinder/connector?command=GetFolders&type=Images¤tFolder=/Docs/
|
Sample response | {
"resourceType": "Images",
"currentFolder": {
"path": "/Docs/",
"url": "/ckfinder/userfiles/images/Docs/",
"acl": 255
},
"folders": [
{
"name": "folder1",
"hasChildren": false,
"acl": 255
},
{
"name": "繁體中文字",
"hasChildren": false,
"acl": 255
}
]
}
|
Notes | Folder names may contain non-ASCII characters, like in the example above with Chinese characters. |
Description | Returns a list of resized versions of the image file. |
Method | GET |
Sample request | Get resized versions of the longcat.jpg image that is stored in the /kittens/ folder of the Images resource type: /ckfinder/connector?command=GetResizedImages&type=Images¤tFolder=/kittens/&fileName=longcat.jpg
|
Sample response | {
"resourceType": "Images",
"currentFolder": {
"path": "/kittens/",
"url": "/ckfinder/userfiles/images/kittens/",
"acl": 255
},
"originalSize":"1920x1200",
"resized": {
"small": "longcat__480x300.jpg",
"medium": "longcat__600x375.jpg",
"large": "longcat__800x500.jpg",
"__custom": ["longcat__200x125.jpg", "longcat__300x188.jpg"]
}
}
|
Notes | The resized versions of images always preserve the aspect ratio of the original. When a resized version of the image matches any size defined in the images.sizes configuration option, it is appended under an appropriate key in the response (like small , medium , large in the example above). All other existing resized versions are stored under the key named __custom . |
Description | Performs basic image modifications: crop, rotate, resize. |
Method | POST |
Sample request | Actions to perform together with required parameters are sent in the An example of the request["actions"] = [
{
"action": "rotate",
"angle": 90 // Number of degrees for clockwise rotation.
},
{
"action": "resize",
"width": 300, // Maximum image width.
"height": 300 // Maximum image height.
},
{
"action": "crop",
"x": 0, // X coordinate of the top-left corner of the cropped area.
"y": 0, // Y coordinate of the top-left corner of the cropped area.
"width": 225, // The cropped area width.
"height": 150 // The cropped area height.
}
]
Depending on whether the
/ckfinder/connector?command=ImageEdit&type=Images¤tFolder=/kittens/&fileName=longcat.jpg
|
Sample response | {
"resourceType": "Images",
"currentFolder": {
"path": "/kittens/",
"url": "/ckfinder/userfiles/images/kittens/",
"acl": 255
},
"saved": 1
}
|
Description | Returns information about the dimensions of the image file. |
Method | GET |
Sample request | Get dimensions of the /ckfinder/connector?command=ImageInfo&type=Images¤tFolder=/kittens/&fileName=longcat.jpg
|
Sample response | {
"resourceType": "Images",
"currentFolder": {
"path": "/kittens/",
"url": "/ckfinder/userfiles/images/kittens/",
"acl": 255
},
"width": 1440,
"height": 900
}
|
Description | Creates a resized version of the image file. |
Method | GET |
Sample request | Create a resized version of the /ckfinder/connector?command=ImagePreview&type=Images¤tFolder=/kittens/&fileName=longcat.jpg&size=450x450
|
Sample response | This command does not expect the connector to return a text response. Instead, it must stream the image data to the client. |
Notes | Returned images always preserve the aspect ratio of the original (using the higher scaling factor calculated for borders). Requested size is corrected when its aspect ratio does not match the aspect ratio of the original image. Images generated with this command are not stored on the server side. |
Description | Creates a resized version of the image file. |
Method | POST |
Sample request | Create a resized version of the /ckfinder/connector?command=ImageResize&type=Images¤tFolder=/kittens/&fileName=longcat.jpg&size=450x450
|
Sample response | {
"resourceType": "Images",
"currentFolder": {
"path": "/kittens/",
"url": "/ckfinder/userfiles/images/kittens/",
"acl": 255
},
"url":"/ckfinder/userfiles/images/kittens/__thumbs/longcat.jpg/longcat__450x281.jpg" // Direct URL to a file
}
|
Notes | Returned images always preserve the aspect ratio of the original (using the lower scaling factor calculated for borders). Requested size is corrected when its aspect ratio does not match the aspect ratio of the original image. Images generated with this command are stored in a special folder named |
Description | This is the first command issued by CKFinder. It returns the general settings of the connector and all configured resource types. |
Method | GET |
Sample request | /ckfinder/connector?command=Init
|
Sample response | {
"enabled": true,
"s": "",
"c": "",
"thumbs": ["150x150", "300x300", "500x500"],
"images":{"max":"500x400","sizes":{"small":"480x320","medium":"600x480","large":"800x600"}},
"uploadMaxSize": "425167",
"uploadCheckImages": true,
"resourceTypes": [
{
"name": "Files",
"url": "/ckfinder/userfiles/files",
"allowedExtensions": "7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,zip",
"deniedExtensions": "",
"hash": "8b787e3ea25b5079",
"hasChildren": false,
"acl": 1023,
"maxSize": 32768
},
{
"name": "Images",
"url": "/ckfinder/userfiles/images",
"allowedExtensions": "bmp,gif,jpeg,jpg,png",
"deniedExtensions": "",
"hash": "b8de0a3f3cb3cd1f",
"hasChildren": false,
"acl": 1023,
"maxSize": 65536
}
]
}
|
Description | Moves files from selected folders. |
Method | POST |
Sample request | Move two files from the Example of the request["files"] = [
{
"name": "file1.jpg",
"type": "Files",
"folder": "/sub1/"
"options": ""
},
{
"name": "file2.png",
"type": "Files",
"folder": "/sub1/"
"options": ""
}
]
/ckfinder/connector?command=MoveFiles&type=Files¤tFolder=/
|
Sample response | {
"resourceType": "Files",
"currentFolder": {
"path": "/",
"url": "/ckfinder/userfiles/files/",
"acl": 255
},
"moved": 2
}
|
Notes | The request should contain an array parameter named files with elements defining source files to be moved. Each array element should contain the following parameters:
|
Description | Tracks the progress of the operation in time-consuming connector commands. |
Method | GET |
Sample request | Progress tracking can be started for a time-consuming command by passing an additional parameter named /ckfinder/connector?command=RenameFolder&type=Files¤tFolder=/foo/&newFolderName=bar&operationId=i52q7a7db83rz3n6
The The status of the operation can be then periodically checked with a request to the /ckfinder/connector?command=Operation&operationId=i52q7a7db83rz3n6
|
Sample response | {
"total": 291,
"current": 128
}
|
Notes | Not all commands support operation tracking and this feature may depend on the storage type defined for a backend. This command may use the following optional parameters:
|
Description | Serves a file to the browser without forcing the download. This command is useful in cases where you want to use files without direct access on a web page. These may be files stored on a backend like a private FTP server, or files that are not in the web server root folder. If the backend is defined as a Note: If you decide to use this option, all links generated by CKFinder will be pointing to the |
Method | GET |
Sample request | /ckfinder/connector?command=Proxy&type=Files¤tFolder=/&fileName=foo.jpg
|
Sample response | This command does not expect the connector to return a text response. Instead, it must stream the file data to the client. |
Notes | This command may use the following optional parameters:
|
Description | Uploads a file to the given folder. This command is very similar to FileUpload and it is used to handle uploads from the CKEditor Image or Link dialog. |
Method | POST |
Sample request | This command accepts an additional URL parameter called Upload a file to the root ( /ckfinder/connector?command=FileUpload&type=Files¤tFolder=/
|
Sample response | {
"resourceType": "Files",
"currentFolder": {
"path": "/",
"url": "/ckfinder/userfiles/files/",
"acl": 255
},
"fileName": "fileName.jpg",
"uploaded": 1
}
|
Notes |
|
Description | Renames a file. |
Method | POST |
Sample request | Rename the file /ckfinder/connector?command=RenameFile&type=Files¤tFolder=/sub1/&fileName=foo.jpg&newFileName=bar.jpg
|
Sample response | {
"resourceType": "Files",
"currentFolder": {
"path": "/sub1/",
"url": "/ckfinder/userfiles/files/sub1/",
"acl": 255
},
"name": "foo.jpg",
"newName":"bar.jpg",
"renamed": 1
}
|
Description | Renames a folder. |
Method | POST |
Sample request | Rename the /ckfinder/connector?command=RenameFolder&type=Files¤tFolder=/sub1/&newFolderName=sub1_renamed
|
Sample response | {
"resourceType": "Files",
"currentFolder": {
"path": "/sub1/",
"url": "/ckfinder/userfiles/files/sub1/",
"acl": 255
},
"newName": "sub1_renamed",
"newPath": "/sub1_renamed/",
"renamed": 1
}
|
Description | Saves a Base64-encoded PNG image to a file. |
Method | POST |
Sample request | Save the Base64-encoded image sent in the /ckfinder/connector?command=SaveImage&type=Files¤tFolder=/&fileName=Test.jpg
|
Sample response | {
"resourceType": "Files",
"currentFolder": {
"path": "/",
"url": "/ckfinder/userfiles/files/",
"acl": 255
},
"saved": 1,
"date": "201406080924",
"size": 1
}
|
Description | Downloads the thumbnail of an image file. |
Method | GET |
Sample request | Download the thumbnail of the file named /ckfinder/connector?command=Thumbnail&type=Files¤tFolder=/&fileName=Test.jpg&size=150x150
|
Response | This command does not expect the connector to return a text response. Instead, it must stream the thumbnail file data to the browser. |
Notes | The
Default sizes can be overwritten in the main configuration file. |