From af8e099dfd28614f14d6879347bd0d1f13f7b7ae Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Tue, 26 May 2015 16:31:05 +0200 Subject: [PATCH] Fixes multipart integration --- binding/form.go | 3 ++- context.go | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/binding/form.go b/binding/form.go index 9d906b3..0cfe874 100644 --- a/binding/form.go +++ b/binding/form.go @@ -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 } diff --git a/context.go b/context.go index 4d03b8b..381bbce 100644 --- a/context.go +++ b/context.go @@ -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 }