add validation for empty file uploads with appropriate error message

This commit is contained in:
Abhinav Raut
2025-11-26 15:25:59 +05:30
parent a279197331
commit 2331a2c970
2 changed files with 7 additions and 0 deletions
+6
View File
@@ -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) {
+1
View File
@@ -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",