Skip to content

Commit 5417919

Browse files
Merge pull request #2241 from liqiang372/fix-avatar-image-oversize
Ticket #2161 - Fix user can upload oversize image to avatar
2 parents 46e23d1 + 24a8f40 commit 5417919

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/shared/components/Settings/Profile/BasicInfo/ImageInput/index.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default class ImageInput extends React.Component {
2424

2525
this.state = {
2626
newBasicInfo: {},
27+
isImageOversize: false,
2728
};
2829
}
2930

@@ -71,6 +72,16 @@ export default class ImageInput extends React.Component {
7172
if (file === undefined) {
7273
return;
7374
}
75+
if (file.size > 2 * 1024 * 1024) {
76+
// If file size is greater than 2 MB, show error message
77+
this.setState({
78+
isImageOversize: true,
79+
});
80+
return;
81+
}
82+
this.setState({
83+
isImageOversize: false,
84+
});
7485
uploadPhotoInit();
7586
loadImage.parseMetaData(file, (data) => {
7687
let orientation = 0;
@@ -115,7 +126,7 @@ export default class ImageInput extends React.Component {
115126
deletingPhoto,
116127
} = profileState;
117128

118-
const { newBasicInfo } = this.state;
129+
const { newBasicInfo, isImageOversize } = this.state;
119130

120131
return (
121132
<div styleName="image">
@@ -146,6 +157,7 @@ export default class ImageInput extends React.Component {
146157
<input type="file" name="image" accept="image/*" onChange={this.onUploadPhoto} id="change-image-input" className="hidden" />
147158
</div>
148159
</div>
160+
{isImageOversize && <div styleName="error-message">Please select an image smaller than 2MB</div>}
149161
</div>
150162
);
151163
}

src/shared/components/Settings/Profile/BasicInfo/ImageInput/styles.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,15 @@
9494
}
9595
}
9696
}
97+
98+
.error-message {
99+
@include roboto-medium;
100+
101+
display: block;
102+
border-radius: 5px;
103+
background-color: $tc-red-10;
104+
color: $tc-red-110;
105+
font-size: 15px;
106+
padding: 15px;
107+
margin: 15px 0;
108+
}

0 commit comments

Comments
 (0)