# Uploading Images in the Editor

## Environment

<table>
    <tbody>
	    <tr>
	    	<td>Product</td>
	    	<td>Progress® Kendo UI for Angular Editor</td>
	    </tr>
    </tbody>
</table>

## Description

How can I upload images in the Kendo UI for Angular Editor?

## Solution

By default, the Kendo UI for Angular Editor does not provide an option for uploading images. However, you can implement this functionality by utilizing the Kendo UI Upload component.

> In this example the selected image files are handled on the client side, that is, no actual upload process is being initiated. You can still re-create the scenario by using a real backend service.

The implementation consists of the following steps:

1. Create a custom [toolbar](https://www.telerik.com/kendo-angular-ui/components/editor/tools#custom-tools) with a button that opens a dialog.

   ```html
   <kendo-editor #editor>
       <kendo-toolbar>
           ...
           <kendo-toolbar-button text="Upload Image" (click)="open()">
           </kendo-toolbar-button>
       </kendo-toolbar>
   </kendo-editor>

   <my-dialog #upload [editor]="editor"></my-dialog>
   ```

2. Configure the Dialog content and add an Upload component inside.

   ```html
   <kendo-upload
       [saveUrl]="uploadSaveUrl"
       [removeUrl]="uploadRemoveUrl"
       (select)="onSelect($event)"
       (remove)="onRemove()"
       [multiple]="false">
           <kendo-upload-messages select="Select images">
           </kendo-upload-messages>
   </kendo-upload>
   ```

3. Read the content of the selected image by using a [`FileReader`](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) in the [`select`](https://www.telerik.com/kendo-angular-ui/components/uploads/api/uploadcomponent#select) event handler of the Upload.

   ```ts
   public onSelect(ev: SelectEvent): void {
       ev.files.forEach((file: FileInfo) => {
           if (file.rawFile) {
               const reader = new FileReader();

               reader.onloadend = () => {
                   let img = new Image();

                   img.src = <string>reader.result;
                   img.onload = () => {
                       this.valueChange.emit({
                           src: img.src,
                           height: img.height,
                           width: img.width
                       });
                   }
               };

               reader.readAsDataURL(file.rawFile);
           }
       });
   }
   ```

4. Execute the `insertImage` command using the URL and the dimensions of the image as its parameters by invoking the [`exec`](https://www.telerik.com/kendo-angular-ui/components/editor/api/editorcomponent#exec) method of the Editor.

   ```ts
   public uploadImage() {
       this.editor.exec('insertImage', this.getData());

       this.close()
   }
   ```

The following example demonstrates the full implementation of the suggested approach.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/knowledge-base/upload-integration/source.txt)
