Uploads Overview

The Upload package contains the FileSelect and Upload components.

Basic Usage

The following example demonstrates the FileSelect and Upload components in action.

import { Component } from '@angular/core';

@Component({
  selector: 'my-uploads',
  template: `
  <div class="example-wrapper">
    <div class="row">
        <div class="col-xs-12 col-sm-6 example-col">
            <p>FileSelect</p>
            <kendo-fileselect>
            </kendo-fileselect>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12 col-sm-6 example-col">
            <p>Upload</p>
            <kendo-upload
                [saveUrl]="uploadSaveUrl"
                [removeUrl]="uploadRemoveUrl">
            </kendo-upload>
        </div>
    </div>
  </div>
  `
})
export class UploadsComponent {
  uploadSaveUrl = 'saveUrl'; // should represent an actual API endpoint
  uploadRemoveUrl = 'removeUrl'; // should represent an actual API endpoint
}
import { Component, Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpProgressEvent, HttpEventType, HttpResponse } from '@angular/common/http';
import { Observable, of, concat } from 'rxjs';
import { delay } from 'rxjs/operators';

@Component({
    selector: 'my-app',
    template: `<my-uploads></my-uploads>`
})
export class AppComponent {
}

/*
  Mocked backend service.
  For further details, check
  https://angular.io/guide/http#writing-an-interceptor
*/

@Injectable()
export class UploadInterceptor implements HttpInterceptor {
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    if (req.url === 'saveUrl') {
      const events: Observable<HttpEvent<any>>[] = [0, 30, 60, 100].map((x) => of(<HttpProgressEvent>{
        type: HttpEventType.UploadProgress,
        loaded: x,
        total: 100
      }).pipe(delay(1000)));

      const success = of(new HttpResponse({ status: 200 })).pipe(delay(1000));
      events.push(success);

      return concat(...events);
    }

    if (req.url === 'removeUrl') {
        return of(new HttpResponse({ status: 200 }));
    }

    return next.handle(req);
  }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { UploadsModule } from '@progress/kendo-angular-upload';
import { UploadsComponent } from './uploads.component';
import { UploadInterceptor } from './app.component';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';


import { AppComponent } from './app.component';

@NgModule({
    imports:      [ BrowserModule, HttpClientModule, UploadsModule, BrowserAnimationsModule, FormsModule, ReactiveFormsModule ],
    declarations: [ AppComponent, UploadsComponent ],
    bootstrap:    [ AppComponent ],
    providers: [
        {
            provide: HTTP_INTERCEPTORS,
            useClass: UploadInterceptor,
            multi: true
        }
    ]
})

export class AppModule { }
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';

enableProdMode();

const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

Installation

Either use the quick setup (Angular CLI v6 or later) or manually add the package (Angular CLI v5 or earlier).

Quick Setup with Angular CLI v6 or Later

Angular CLI v6 supports the addition of packages through the ng add command which executes in one step the set of otherwise individually needed commands.

ng add @progress/kendo-angular-upload

Manual Setup

  1. Download and install the package.

    npm install --save @progress/kendo-angular-upload @progress/kendo-angular-common @progress/kendo-angular-l10n
  2. Once installed, import the HttpClientModule and the NgModule of the components you need.

    To get all package components, import the UploadsModule in your application root or feature module.

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { HttpClientModule } from '@angular/common/http';
    import { UploadsModule } from '@progress/kendo-angular-upload';
    import { AppComponent } from './app.component';
    
    @NgModule({
       bootstrap:    [AppComponent],
       declarations: [AppComponent],
       imports:      [BrowserModule, BrowserAnimationsModule, HttpClientModule, UploadsModule]
    })
    export class AppModule {
    }

    The package also exports the following modules for individual components:

    • FileSelectModule
    • UploadModule

    To reduce the size of your application, include only the ones you need.

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { HttpClientModule } from '@angular/common/http';
    import { FileSelectModule } from '@progress/kendo-angular-upload';
    import { AppComponent } from './app.component';
    
    @NgModule({
       bootstrap:    [AppComponent],
       declarations: [AppComponent],
       imports:      [BrowserModule, BrowserAnimationsModule, HttpClientModule, FileSelectModule]
    })
    export class AppModule {
    }
  3. You are required to install one of the Kendo UI themes for Angular to style your component. For more information on how to add the styles, refer to the section on styling.

  4. For Angular 9.x and later, install the @angular/localize package:

    1. Run npm install --save @angular/localize.
    2. Add import '@angular/localize/init'; to your src/polyfills.ts file.

Dependencies

The Upload package requires you to install the following peer dependencies in your application:

  • @angular/animations
  • @angular/common
  • @angular/core
  • @angular/forms
  • @progress/kendo-angular-common
  • @progress/kendo-angular-l10n
  • rxjs

The Upload package utilizes the Angular animation system, which supports a specific set of browsers.

In this article