From 6e08669d22cce01a4b1e54c64bc236899c959163 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 14 Dec 2015 15:35:08 -0500 Subject: [PATCH 1/2] Added clientside check for profile image size --- web/react/components/user_settings/user_settings_general.jsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/react/components/user_settings/user_settings_general.jsx b/web/react/components/user_settings/user_settings_general.jsx index 7c1a1297f7..c47f7d33d0 100644 --- a/web/react/components/user_settings/user_settings_general.jsx +++ b/web/react/components/user_settings/user_settings_general.jsx @@ -9,6 +9,7 @@ import UserStore from '../../stores/user_store.jsx'; import ErrorStore from '../../stores/error_store.jsx'; import * as Client from '../../utils/client.jsx'; +import Constants from '../../utils/constants.jsx'; import * as AsyncClient from '../../utils/async_client.jsx'; import * as Utils from '../../utils/utils.jsx'; @@ -156,8 +157,12 @@ export default class UserSettingsGeneralTab extends React.Component { if (picture.type !== 'image/jpeg' && picture.type !== 'image/png') { this.setState({clientError: 'Only JPG or PNG images may be used for profile pictures.'}); return; + } else if (picture.size > Constants.MAX_FILE_SIZE) { + this.setState({clientError: 'Unable to upload profile image. File is too large.'}); + return; } + var formData = new FormData(); formData.append('image', picture, picture.name); this.setState({loadingPicture: true}); From 76e1f1f6138de9cfea03847af0eff61a10261043 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 14 Dec 2015 16:04:10 -0500 Subject: [PATCH 2/2] Added serverside file size check for post attachments --- api/file.go | 6 ++++++ .../components/user_settings/user_settings_general.jsx | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/api/file.go b/api/file.go index 8afc706926..4339e610b5 100644 --- a/api/file.go +++ b/api/file.go @@ -76,6 +76,12 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) { return } + if r.ContentLength > model.MAX_FILE_SIZE { + c.Err = model.NewAppError("uploadFile", "Unable to upload file. File is too large.", "") + c.Err.StatusCode = http.StatusRequestEntityTooLarge + return + } + err := r.ParseMultipartForm(model.MAX_FILE_SIZE) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/web/react/components/user_settings/user_settings_general.jsx b/web/react/components/user_settings/user_settings_general.jsx index c47f7d33d0..014038dd4b 100644 --- a/web/react/components/user_settings/user_settings_general.jsx +++ b/web/react/components/user_settings/user_settings_general.jsx @@ -162,7 +162,6 @@ export default class UserSettingsGeneralTab extends React.Component { return; } - var formData = new FormData(); formData.append('image', picture, picture.name); this.setState({loadingPicture: true});