Displaying a Download URL Link on a File Upload
Environment
| Product | Progress® Kendo UI® Upload for Angular |
Description
How can I show a download URL link after a successful file upload when using Kendo UI for Angular Upload?
This Knowledge Base article also answers the following questions:
- How can I create a download link for an uploaded file?
- How can I display a clickable URL after file upload completes?
- How can I make uploaded file names into download links?
Solution
To display a URL link after successfully uploading a file:
-
Handle the
successevent of the Upload component.html<kendo-upload (success)="onSuccess($event)" >...</kendo-upload> -
To access the download URL link returned from the server, use the SuccessEvent
response.bodyproperty in thesuccessevent handler.tspublic onSuccess(ev: SuccessEvent): void { let urlLink: string = ev.response.body; } -
Pass the URL link to a custom field of the uploaded file (
downloadUrlin this case).tslet file: any = ev.files[0]; file.downloadUrl = urlLink ; -
Use the
kendoUploadFileInfoTemplatedirective to customize the content of the uploaded file and access the URL link in the template.html<ng-template kendoUploadFileInfoTemplate let-files ...> <a href="{{ files[0].downloadUrl }}">{{ files[0].name }}</a> </ng-template> -
Depending on the
statefield passed by thekendoUploadFileInfoTemplate, switch between the default file text and the anchor link.html<ng-template kendoUploadFileInfoTemplate ... let-state="state"> <span *ngIf="!isUploaded(state)"> {{ files[0].name }} </span> <a ... *ngIf="isUploaded(state)"> {{ files[0].name }} </a> </ng-template>tspublic isUploaded(state: FileState): boolean { return state === FileState.Uploaded ? true : false; }
The following example demonstrates the full implementation of the suggested approach.