|
| 1 | +--- |
| 2 | +title: Image Browser |
| 3 | +page_title: Editor Image Browser | Telerik UI for ASP.NET Core HtmlHelpers |
| 4 | +description: "Learn about the Image Browser component of the Kendo UI Editor HtmlHelper for ASP.NET Core (MVC 6 or ASP.NET Core MVC)." |
| 5 | +slug: htmlhelpers_editor_image_browser_aspnetcore |
| 6 | +position: 6 |
| 7 | +--- |
| 8 | + |
| 9 | +# Image Browser |
| 10 | + |
| 11 | +By default, the `Insert Image` tool opens a simple dialog that allows you to type in or paste the URL of an image and, optionally, specify a tooltip. |
| 12 | + |
| 13 | +The Editor also supports another way of picking an image by browsing a list of predefined files and directories. Uploading new images is also supported. |
| 14 | + |
| 15 | +## Configuration |
| 16 | + |
| 17 | +To retrieve and upload the files and directories, the image browser needs a server-side implementation. |
| 18 | + |
| 19 | +The image browser tool can be configured through the [`ImageBrowser()`](/api/Kendo.Mvc.UI.Fluent/EditorBuilder#imagebrowsersystemactionkendomvcuifluenteditorimagebrowsersettingsbuilder) configuration method. |
| 20 | + |
| 21 | +###### Example |
| 22 | + |
| 23 | +``` |
| 24 | +@(Html.Kendo().Editor() |
| 25 | + .Name("editor") |
| 26 | + .ImageBrowser(imageBrowser => imageBrowser |
| 27 | + .Image("~/Content/UserFiles/Images/{0}") |
| 28 | + .Read("Read", "ImageBrowser") |
| 29 | + .Create("Create", "ImageBrowser") |
| 30 | + .Destroy("Destroy", "ImageBrowser") |
| 31 | + .Upload("Upload", "ImageBrowser") |
| 32 | + .Thumbnail("Thumbnail", "ImageBrowser") |
| 33 | + ) |
| 34 | +) |
| 35 | +``` |
| 36 | + |
| 37 | +The following list provides information about the default requests and responses for the `Create()`, `Read()`, `Destroy()`, and `Upload()` operations. |
| 38 | + |
| 39 | +- `Create()`—Makes a `POST` request for the creation of a directory with the following parameters and does not expect a response. |
| 40 | + |
| 41 | + { "name": "New folder name", "type": "d", "path": "foo/" } |
| 42 | + |
| 43 | +- `Read()`—Makes a `POST` request that contains the `path` parameter to specify the path which is browsed and expects a file listing in the following format. |
| 44 | + |
| 45 | + ``` |
| 46 | + [ |
| 47 | + { "name": "foo.png", "type": "f", "size": 73289 }, |
| 48 | + { "name": "bar.jpg", "type": "f", "size": 15289 }, |
| 49 | + ... |
| 50 | + ] |
| 51 | + ``` |
| 52 | +
|
| 53 | + Where `name` is the file or directory name, `type` is either an **f** for a file or a **d** for a directory, and `size` is the file size (optional). |
| 54 | +
|
| 55 | +- `Destroy()`—Makes a `POST` request with the following parameters: |
| 56 | +
|
| 57 | + - `name`—The file or directory to be deleted. |
| 58 | + - `path`—The directory in which the file or the directory resides. |
| 59 | + - `type`—Whether a file or a directory is to be deleted (an **f** or a **d**). |
| 60 | + - `size`—(Optional) The file size, as provided by the `Read()` response. |
| 61 | +
|
| 62 | +- `Upload()`—Makes a `POST` request. The request contains `FormData` containing the upload path, file name and type. Its payload consists of the uploaded file. The expected response is a `file` object in the following format: |
| 63 | +
|
| 64 | + ``` |
| 65 | + { "name": "foo.png", "type": "f", "size": 12345 } |
| 66 | + ``` |
| 67 | +
|
| 68 | +- `Thumbnail()`—Makes a `GET` request for each individual image in order to display its thumbnail in the explorer window. The single request parameter is the `path` to the image. The service is expected to respond with the image file for the thumbnail. |
| 69 | +
|
| 70 | +- `Image()`—Used by the Editor to generate the `src` attribute of the original image when it is inserted. It results in a `GET` request generated by the browser for each inserted image. The URL can point to a file system or to a service and is parameterized—the `{0}` placeholder denotes the `path` and `fileName` as received from the `Read()` service. |
| 71 | +
|
| 72 | +You can update all of these requests and responses through the [`ImageBrowser()`](/api/Kendo.Mvc.UI.Fluent/EditorBuilder#imagebrowsersystemactionkendomvcuifluenteditorimagebrowsersettingsbuilder) configuration. Each of them exposes more options that you can tweak. |
| 73 | +
|
| 74 | +## See Also |
| 75 | +
|
| 76 | +* [Overview of the Editor HtmlHelper]({% slug htmlhelpers_editor_aspnetcore %}) |
| 77 | +* [Modes of Operation]({% slug htmlhelpers_editor_modes_aspnetcore %}) |
| 78 | +* [Tools]({% slug htmlhelpers_editor_tools_aspnetcore %}) |
| 79 | +* [Pasting Content]({% slug htmlhelpers_editor_pasting_aspnetcore %}) |
| 80 | +* [Serialize / Deserialize Content]({% slug htmlhelpers_editor_serialize_aspnetcore %}) |
| 81 | +* [Immutable Elements]({% slug htmlhelpers_editor_immutable_aspnetcore %}) |
| 82 | +* [Styling Content]({% slug htmlhelpers_editor_styling_aspnetcore %}) |
0 commit comments