Skip to content

Commit 1f49b21

Browse files
committed
Fix file upload size limit for large media files
The request size middleware was applying a 10MB limit to all requests including multipart file uploads. This caused uploads of larger media files (like 17MB MP4s) to fail with "No file provided" error. Fixed by detecting multipart/form-data Content-Type and applying the maxFileSize (5GB) limit for file uploads instead of the smaller maxRequestBodyMB limit.
1 parent 4fe5fc1 commit 1f49b21

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cmd/ffprobe-api/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,17 @@ func securityHeadersMiddleware() gin.HandlerFunc {
312312
}
313313

314314
// requestSizeLimitMiddleware limits request body size
315+
// Note: Multipart form requests (file uploads) are excluded - they use maxFileSize limit
315316
func requestSizeLimitMiddleware(maxBytes int64) gin.HandlerFunc {
316317
return func(c *gin.Context) {
317-
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxBytes)
318+
// Skip limit for multipart form data (file uploads)
319+
contentType := c.GetHeader("Content-Type")
320+
if strings.HasPrefix(contentType, "multipart/form-data") {
321+
// For file uploads, use the much larger maxFileSize limit
322+
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxFileSize)
323+
} else {
324+
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxBytes)
325+
}
318326
c.Next()
319327
}
320328
}

0 commit comments

Comments
 (0)