From e1cadce44ec73f31434a96b60b2d05e4e1e62e3c Mon Sep 17 00:00:00 2001 From: maggiehuiliyao Date: Sun, 15 Jan 2023 19:18:47 -0500 Subject: [PATCH] avatar and resume file size chck --- frontend/src/components/avatarUpload.js | 6 +++--- frontend/src/views/account.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/avatarUpload.js b/frontend/src/components/avatarUpload.js index 179d0e3f6..385ddfdc3 100644 --- a/frontend/src/components/avatarUpload.js +++ b/frontend/src/components/avatarUpload.js @@ -28,10 +28,10 @@ class AvatarUpload extends Component { } else { this.setState({ status: "failure" }); } - setTimeout(() => { - this.setState({ status: "waiting" }); - }, 2000); }); + setTimeout(() => { + this.setState({ status: "waiting" }); + }, 2000); } render() { diff --git a/frontend/src/views/account.js b/frontend/src/views/account.js index a7f3f9b9b..b12bf0734 100644 --- a/frontend/src/views/account.js +++ b/frontend/src/views/account.js @@ -102,6 +102,16 @@ class Account extends Component { } uploadResume = () => { + const fileSize = this.state.selectedResumeFile.size / 1024 / 1024; // in MiB + if (fileSize > 5) { + let alert_message = + "Ensure this file size is not greater than 5 MiB. Your current file size is " + + Number(fileSize.toPrecision(3)) + + " MiB."; + this.setState({ alert_message: alert_message }); + this.setState({ resume_status: "waiting" }); + return; + } this.setState({ resume_status: "loading" }); Api.resumeUpload(this.state.selectedResumeFile, (success) => { if (success) { @@ -117,6 +127,15 @@ class Account extends Component { }; uploadAvatar = (selected_file, callback) => { + const fileSize = selected_file.size / 1024 / 1024; // in MiB + if (fileSize > 5) { + let alert_message = + "Ensure this file size is not greater than 5 MiB. Your current file size is " + + Number(fileSize.toPrecision(3)) + + " MiB."; + this.setState({ alert_message: alert_message }); + return; + } Api.avatarUpload(selected_file, (response, success) => { if (success) { this.props.updateBaseState();