mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-11 13:28:57 +00:00
add validation for empty file uploads with appropriate error message
This commit is contained in:
@@ -66,6 +66,12 @@ func handleMediaUpload(r *fastglue.Request) error {
|
||||
srcFileSize := fileHeader.Size
|
||||
srcExt := strings.TrimPrefix(strings.ToLower(filepath.Ext(srcFileName)), ".")
|
||||
|
||||
// Check if file is empty
|
||||
if srcFileSize == 0 {
|
||||
app.lo.Error("error: uploaded file is empty (0 bytes)")
|
||||
return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.T("media.fileEmpty"), nil, envelope.InputError)
|
||||
}
|
||||
|
||||
// Check file size
|
||||
consts := app.consts.Load().(*constants)
|
||||
if bytesToMegabytes(srcFileSize) > float64(consts.MaxFileUploadSizeMB) {
|
||||
|
||||
@@ -332,6 +332,7 @@
|
||||
"user.errorGeneratingPasswordToken": "Error generating password token",
|
||||
"media.fileSizeTooLarge": "File size too large, please upload a file less than {size} ",
|
||||
"media.fileTypeNotAllowed": "File type not allowed",
|
||||
"media.fileEmpty": "This file is 0 bytes, so it will not be attached.",
|
||||
"inbox.emptyIMAP": "Empty IMAP config",
|
||||
"inbox.emptySMTP": "Empty SMTP config",
|
||||
"template.defaultTemplateAlreadyExists": "Default template already exists",
|
||||
|
||||
Reference in New Issue
Block a user