Skip to content

Commit 0221b13

Browse files
committed
fix(api/v2): align avatar upload body limit with global overhead
MaxBodyBytes was set to exactly the configured max file size, but a multipart request carries extra bytes (boundary, part headers) on top of the file, so a file at the limit could be rejected by Huma before the handler runs. Mirror the +2 MB overhead that Echo's global BodyLimit middleware already allows so a max-sized avatar isn't rejected.
1 parent 612c247 commit 0221b13

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

pkg/routes/api/v2/avatar_upload.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ func RegisterAvatarRoutes(api huma.API) {
6868
Tags: tags,
6969
// Avatars can be larger than Huma's 1 MB default body limit; allow up to
7070
// the configured max file size so legitimate uploads aren't rejected before
71-
// the handler runs. Echo's global BodyLimit middleware still caps the total.
71+
// the handler runs. The total multipart request is larger than the file
72+
// itself (boundary, part headers), so mirror the +2 MB overhead Echo's
73+
// global BodyLimit middleware (pkg/routes/routes.go) already allows;
74+
// otherwise a file at exactly the limit could be rejected by Huma.
7275
// #nosec G115 - configured value won't exceed int64 max in practice.
73-
MaxBodyBytes: int64(config.GetMaxFileSizeInMBytes()) * 1024 * 1024,
76+
MaxBodyBytes: (int64(config.GetMaxFileSizeInMBytes()) + 2) * 1024 * 1024,
7477
DefaultStatus: http.StatusOK,
7578
}, avatarUpload)
7679
}

0 commit comments

Comments
 (0)