From c0ce20f65ddaee9f8b22ef9248060babd94ef163 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 19 Jan 2020 00:09:52 +0100 Subject: [PATCH] Fix upload is permitted without a file being selected --- .../fileUpload/fileUpload.component.ts | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/app/components/profile/fileUpload/fileUpload.component.ts b/src/app/components/profile/fileUpload/fileUpload.component.ts index b86767c..b4b5bf0 100644 --- a/src/app/components/profile/fileUpload/fileUpload.component.ts +++ b/src/app/components/profile/fileUpload/fileUpload.component.ts @@ -39,27 +39,32 @@ export class DialogFileUploadComponent { * Fired when the ok button was pressed */ onOkClicked() { - this.errorOccurred = false; - this.uploading = true; - this.selfService.changeProfilePicture(this.file).subscribe((response) => { - this.uploading = false; - if (response.success) { - this.profilePictureUrl.next(environment.greenvironmentUrl + response.fileName); - this.dialogRef.close(); - } else { - this.errorMessage = response.error; + if (this.file) { + this.errorOccurred = false; + this.uploading = true; + this.selfService.changeProfilePicture(this.file).subscribe((response) => { + this.uploading = false; + if (response.success) { + this.profilePictureUrl.next(environment.greenvironmentUrl + response.fileName); + this.dialogRef.close(); + } else { + this.errorMessage = response.error; + this.errorOccurred = true; + } + }, (error) => { + this.uploading = false; this.errorOccurred = true; - } - }, (error) => { - this.uploading = false; + console.log(error); + if (error.error) { + this.errorMessage = error.error.error; + } else { + this.errorMessage = 'Failed to upload the profile picture.'; + } + }); + } else { this.errorOccurred = true; - console.log(error); - if (error.error) { - this.errorMessage = error.error.error; - } else { - this.errorMessage = 'Failed to upload the profile picture.'; - } - }); + this.errorMessage = 'Please select a file to upload.'; + } } /**