Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
99055bab
authored
Nov 16, 2025
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: boundary parser error (error parsing multipart form: multipart: NextPart: bufio: buffer full)
parent
9009a572
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
12 deletions
+41
-12
common/gin.go
+41
-12
No files found.
common/gin.go
View file @
99055bab
...
...
@@ -2,7 +2,9 @@ package common
import
(
"bytes"
"errors"
"io"
"mime"
"mime/multipart"
"net/http"
"net/url"
...
...
@@ -128,13 +130,13 @@ func ParseMultipartFormReusable(c *gin.Context) (*multipart.Form, error) {
}
contentType
:=
c
.
Request
.
Header
.
Get
(
"Content-Type"
)
boundary
:=
""
if
idx
:=
strings
.
Index
(
contentType
,
"boundary="
);
idx
!=
-
1
{
boundary
=
contentType
[
idx
+
9
:
]
boundary
,
err
:=
parseBoundary
(
contentType
)
if
err
!=
nil
{
return
nil
,
err
}
reader
:=
multipart
.
NewReader
(
bytes
.
NewReader
(
requestBody
),
boundary
)
form
,
err
:=
reader
.
ReadForm
(
32
<<
20
)
// 32 MB max memory
form
,
err
:=
reader
.
ReadForm
(
multipartMemoryLimit
())
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -177,17 +179,16 @@ func parseFormData(data []byte, v any) error {
func
parseMultipartFormData
(
c
*
gin
.
Context
,
data
[]
byte
,
v
any
)
error
{
contentType
:=
c
.
Request
.
Header
.
Get
(
"Content-Type"
)
boundary
:=
""
if
idx
:=
strings
.
Index
(
contentType
,
"boundary="
);
idx
!=
-
1
{
boundary
=
contentType
[
idx
+
9
:
]
}
if
boundary
==
""
{
return
Unmarshal
(
data
,
v
)
// Fallback to JSON
boundary
,
err
:=
parseBoundary
(
contentType
)
if
err
!=
nil
{
if
errors
.
Is
(
err
,
errBoundaryNotFound
)
{
return
Unmarshal
(
data
,
v
)
// Fallback to JSON
}
return
err
}
reader
:=
multipart
.
NewReader
(
bytes
.
NewReader
(
data
),
boundary
)
form
,
err
:=
reader
.
ReadForm
(
32
<<
20
)
// 32 MB max memory
form
,
err
:=
reader
.
ReadForm
(
multipartMemoryLimit
())
if
err
!=
nil
{
return
err
}
...
...
@@ -203,3 +204,31 @@ func parseMultipartFormData(c *gin.Context, data []byte, v any) error {
return
processFormMap
(
formMap
,
v
)
}
var
errBoundaryNotFound
=
errors
.
New
(
"multipart boundary not found"
)
// parseBoundary extracts the multipart boundary from the Content-Type header using mime.ParseMediaType
func
parseBoundary
(
contentType
string
)
(
string
,
error
)
{
if
contentType
==
""
{
return
""
,
errBoundaryNotFound
}
// Boundary-UUID / boundary-------xxxxxx
_
,
params
,
err
:=
mime
.
ParseMediaType
(
contentType
)
if
err
!=
nil
{
return
""
,
err
}
boundary
,
ok
:=
params
[
"boundary"
]
if
!
ok
||
boundary
==
""
{
return
""
,
errBoundaryNotFound
}
return
boundary
,
nil
}
// multipartMemoryLimit returns the configured multipart memory limit in bytes
func
multipartMemoryLimit
()
int64
{
limitMB
:=
constant
.
MaxFileDownloadMB
if
limitMB
<=
0
{
limitMB
=
32
}
return
int64
(
limitMB
)
<<
20
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment