mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Max_File_Size setting in System Console > File Settings (#3070)
This commit is contained in:
committed by
Harrison Healey
parent
8e5c318590
commit
7e2b539de4
@@ -437,13 +437,13 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if r.ContentLength > model.MAX_FILE_SIZE {
|
||||
if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
|
||||
c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.too_large.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusRequestEntityTooLarge
|
||||
return
|
||||
}
|
||||
|
||||
if err := r.ParseMultipartForm(model.MAX_FILE_SIZE); err != nil {
|
||||
if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil {
|
||||
c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.parse.app_error", nil, "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -77,13 +77,13 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if r.ContentLength > model.MAX_FILE_SIZE {
|
||||
if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
|
||||
c.Err = model.NewLocAppError("uploadFile", "api.file.upload_file.too_large.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusRequestEntityTooLarge
|
||||
return
|
||||
}
|
||||
|
||||
err := r.ParseMultipartForm(model.MAX_FILE_SIZE)
|
||||
err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -5,12 +5,13 @@ package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -48,7 +49,7 @@ func LoadLicense() {
|
||||
|
||||
func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("attempt")
|
||||
err := r.ParseMultipartForm(model.MAX_FILE_SIZE)
|
||||
err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -1178,13 +1178,13 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if r.ContentLength > model.MAX_FILE_SIZE {
|
||||
if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
|
||||
c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.too_large.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusRequestEntityTooLarge
|
||||
return
|
||||
}
|
||||
|
||||
if err := r.ParseMultipartForm(model.MAX_FILE_SIZE); err != nil {
|
||||
if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil {
|
||||
c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.parse.app_error", nil, "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
"FileLocation": ""
|
||||
},
|
||||
"FileSettings": {
|
||||
"MaxFileSize": 52428800,
|
||||
"DriverName": "local",
|
||||
"Directory": "./data/",
|
||||
"EnablePublicLink": false,
|
||||
@@ -160,4 +161,4 @@
|
||||
"DefaultClientLocale": "en",
|
||||
"AvailableLocales": "en,es,fr,ja,pt-BR"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2391,6 +2391,10 @@
|
||||
"id": "model.config.is_valid.sql_idle.app_error",
|
||||
"translation": "Invalid maximum idle connection for SQL settings. Must be a positive number."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.max_file_size.app_error",
|
||||
"translation": "Invalid max file size for file settings. Must be a zero or positive number."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.sql_max_conn.app_error",
|
||||
"translation": "Invalid maximum open connection for SQL settings. Must be a positive number."
|
||||
|
||||
@@ -92,6 +92,7 @@ type LogSettings struct {
|
||||
}
|
||||
|
||||
type FileSettings struct {
|
||||
MaxFileSize *int64
|
||||
DriverName string
|
||||
Directory string
|
||||
EnablePublicLink bool
|
||||
@@ -263,6 +264,11 @@ func (o *Config) SetDefaults() {
|
||||
o.SqlSettings.AtRestEncryptKey = NewRandomString(32)
|
||||
}
|
||||
|
||||
if o.FileSettings.MaxFileSize == nil {
|
||||
o.FileSettings.MaxFileSize = new(int64)
|
||||
*o.FileSettings.MaxFileSize = 52428800 // 50 MB
|
||||
}
|
||||
|
||||
if len(o.FileSettings.PublicLinkSalt) == 0 {
|
||||
o.FileSettings.PublicLinkSalt = NewRandomString(32)
|
||||
}
|
||||
@@ -569,6 +575,10 @@ func (o *Config) IsValid() *AppError {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_max_conn.app_error", nil, "")
|
||||
}
|
||||
|
||||
if *o.FileSettings.MaxFileSize <= 0 {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.max_file_size.app_error", nil, "")
|
||||
}
|
||||
|
||||
if !(o.FileSettings.DriverName == IMAGE_DRIVER_LOCAL || o.FileSettings.DriverName == IMAGE_DRIVER_S3) {
|
||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.file_driver.app_error", nil, "")
|
||||
}
|
||||
|
||||
@@ -8,10 +8,6 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
MAX_FILE_SIZE = 50000000 // 50 MB
|
||||
)
|
||||
|
||||
var (
|
||||
IMAGE_EXTENSIONS = [5]string{".jpg", ".jpeg", ".gif", ".bmp", ".png"}
|
||||
IMAGE_MIME_TYPES = map[string]string{".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".bmp": "image/bmp", ".png": "image/png", ".tiff": "image/tiff"}
|
||||
|
||||
@@ -23,6 +23,7 @@ export default class StorageSettings extends AdminSettings {
|
||||
this.renderSettings = this.renderSettings.bind(this);
|
||||
|
||||
this.state = Object.assign(this.state, {
|
||||
maxFileSize: props.config.FileSettings.MaxFileSize,
|
||||
driverName: props.config.FileSettings.DriverName,
|
||||
directory: props.config.FileSettings.Directory,
|
||||
amazonS3AccessKeyId: props.config.FileSettings.AmazonS3AccessKeyId,
|
||||
@@ -33,6 +34,7 @@ export default class StorageSettings extends AdminSettings {
|
||||
}
|
||||
|
||||
getConfigFromState(config) {
|
||||
config.FileSettings.MaxFileSize = this.parseInt(this.state.maxFileSize);
|
||||
config.FileSettings.DriverName = this.state.driverName;
|
||||
config.FileSettings.Directory = this.state.directory;
|
||||
config.FileSettings.AmazonS3AccessKeyId = this.state.amazonS3AccessKeyId;
|
||||
@@ -64,6 +66,24 @@ export default class StorageSettings extends AdminSettings {
|
||||
/>
|
||||
}
|
||||
>
|
||||
<TextSetting
|
||||
id='maxFileSize'
|
||||
label={
|
||||
<FormattedMessage
|
||||
id='admin.image.maxFileSizeTitle'
|
||||
defaultMessage='Max File Size:'
|
||||
/>
|
||||
}
|
||||
placeholder={Utils.localizeMessage('admin.image.maxFileSizeExample', 'Ex "52428800"')}
|
||||
helpText={
|
||||
<FormattedMessage
|
||||
id='admin.image.maxFileSizeDescription'
|
||||
defaultMessage='Max File Size in bytes. If blank, will be set to 52428800 (50MB).'
|
||||
/>
|
||||
}
|
||||
value={this.state.maxFileSize}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
<DropdownSetting
|
||||
id='driverName'
|
||||
values={[
|
||||
@@ -177,4 +197,4 @@ export default class StorageSettings extends AdminSettings {
|
||||
</SettingsGroup>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user