mirror of https://github.com/gin-gonic/gin.git
Fixes multipart integration
This commit is contained in:
parent
500d745123
commit
af8e099dfd
|
@ -9,13 +9,14 @@ import "net/http"
|
|||
type formBinding struct{}
|
||||
|
||||
func (_ formBinding) Name() string {
|
||||
return "query"
|
||||
return "form"
|
||||
}
|
||||
|
||||
func (_ formBinding) Bind(req *http.Request, obj interface{}) error {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return err
|
||||
}
|
||||
req.ParseMultipartForm(32 << 10) // 32 MB
|
||||
if err := mapForm(obj, req.Form); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -232,11 +232,13 @@ func (c *Context) query(key string) (string, bool) {
|
|||
func (c *Context) postForm(key string) (string, bool) {
|
||||
req := c.Request
|
||||
req.ParseMultipartForm(32 << 20) // 32 MB
|
||||
if values, ok := req.PostForm[key]; ok && len(values) > 0 {
|
||||
if values := req.PostForm[key]; len(values) > 0 {
|
||||
return values[0], true
|
||||
}
|
||||
if values, ok := req.MultipartForm.Value[key]; ok && len(values) > 0 {
|
||||
return values[0], true
|
||||
if req.MultipartForm != nil && req.MultipartForm.File != nil {
|
||||
if values := req.MultipartForm.Value[key]; len(values) > 0 {
|
||||
return values[0], true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue