New to Kendo UI for Angular? Start a free 30-day trial
Creating a Download Link for an Uploaded File
Environment
| Product | Progress® Kendo UI for Angular Upload | 
Description
How can I create a download link for an uploaded file by using Kendo UI for Angular Upload?
Solution
To display a download link after the file has been successfully uploaded:
- 
Handle the successevent of the component:- Return the download URL as a response from the server.
- In the event handler, assign the download URL to a custom field of the uploaded file.
tspublic onSuccess(ev: SuccessEvent): void { let file: FileInfo | any = ev.files[0]; file.downloadURL = 'myURL'; }
 
- 
To change the default file name to a download link, use the FileInfoTemplate. To access the download URL, get thefilesfield of the template.html<kendo-upload [saveUrl]="uploadSaveUrl" [removeUrl]="uploadRemoveUrl"> <ng-template kendoUploadFileInfoTemplate let-files> <span *ngIf="!isUploaded(state)">{{ files[0].name }}</span> <a href="{{ files[0].downloadURL }}" *ngIf="isUploaded(state)">{{ files[0].name }}</a> </ng-template> </kendo-upload>
- 
To toggle the visibility of the file name and the download link based on the file upload status, use the *ngIfAngular directive.tspublic isUploaded(state: FileState): boolean { return state === FileState.Uploaded ? true : false; }
The following example demonstrates the suggested approach.
Change Theme
Theme
Loading ...