Restore multipart/form-data support

This commit is contained in:
konjoot 2015-05-23 16:52:09 +03:00
parent 35fd7fb480
commit 8b426d0b3a
2 changed files with 31 additions and 3 deletions

View File

@ -28,9 +28,10 @@ type Binding interface {
var validate = validator.New("binding", validator.BakedInValidators)
var (
JSON = jsonBinding{}
XML = xmlBinding{}
Form = formBinding{}
XML = xmlBinding{}
JSON = jsonBinding{}
Form = formBinding{}
MultipartForm = MultipartFormBinding{}
)
func Default(method, contentType string) Binding {
@ -42,6 +43,8 @@ func Default(method, contentType string) Binding {
return JSON
case MIMEXML, MIMEXML2:
return XML
case MIMEMultipartPOSTForm:
return MultipartForm
default:
return Form
}

25
binding/form_multipart.go Normal file
View File

@ -0,0 +1,25 @@
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package binding
import "net/http"
const MAX_MEMORY = 1 * 1024 * 1024
type multipartFormBinding struct{}
func (_ multipartFormBinding) Name() string {
return "multipart form"
}
func (_ multipartFormBinding) Bind(req *http.Request, obj interface{}) error {
if err := req.ParseMultipartForm(MAX_MEMORY); err != nil {
return err
}
if err := mapForm(obj, req.Form); err != nil {
return err
}
return Validate(obj)
}