Fixes multipart integration

This commit is contained in:
Manu Mtz-Almeida 2015-05-26 16:31:05 +02:00
parent 500d745123
commit af8e099dfd
2 changed files with 7 additions and 4 deletions

View File

@ -9,13 +9,14 @@ import "net/http"
type formBinding struct{} type formBinding struct{}
func (_ formBinding) Name() string { func (_ formBinding) Name() string {
return "query" return "form"
} }
func (_ formBinding) Bind(req *http.Request, obj interface{}) error { func (_ formBinding) Bind(req *http.Request, obj interface{}) error {
if err := req.ParseForm(); err != nil { if err := req.ParseForm(); err != nil {
return err return err
} }
req.ParseMultipartForm(32 << 10) // 32 MB
if err := mapForm(obj, req.Form); err != nil { if err := mapForm(obj, req.Form); err != nil {
return err return err
} }

View File

@ -232,12 +232,14 @@ func (c *Context) query(key string) (string, bool) {
func (c *Context) postForm(key string) (string, bool) { func (c *Context) postForm(key string) (string, bool) {
req := c.Request req := c.Request
req.ParseMultipartForm(32 << 20) // 32 MB 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 return values[0], true
} }
if values, ok := req.MultipartForm.Value[key]; ok && len(values) > 0 { if req.MultipartForm != nil && req.MultipartForm.File != nil {
if values := req.MultipartForm.Value[key]; len(values) > 0 {
return values[0], true return values[0], true
} }
}
return "", false return "", false
} }