Improve file too large error handling

This commit is contained in:
Dominic Ferrando
2025-04-22 21:26:33 -04:00
parent 0c657ae1c5
commit 4018632080
2 changed files with 23 additions and 40 deletions
-14
View File
@@ -261,17 +261,3 @@ func FormatFileInfo(fileInfo PostFileInfo) string {
}
return fmt.Sprintf("(%s, %dx%d)", humanSize, fileInfo.Width, fileInfo.Height)
}
func IsMediaTooLarge(file multipart.File) (bool, error) {
limitedReader := io.LimitReader(file, FILE_MEM_LIMIT+1)
fileBytes, err := io.ReadAll(limitedReader)
if err != nil {
return true, err
}
if int64(len(fileBytes)) > FILE_MEM_LIMIT {
return true, nil
}
return false, nil
}