mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 13:02:14 +08:00
Restore multipart/form-data support
This commit is contained in:
parent
35fd7fb480
commit
8b426d0b3a
@ -28,9 +28,10 @@ type Binding interface {
|
|||||||
var validate = validator.New("binding", validator.BakedInValidators)
|
var validate = validator.New("binding", validator.BakedInValidators)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
JSON = jsonBinding{}
|
XML = xmlBinding{}
|
||||||
XML = xmlBinding{}
|
JSON = jsonBinding{}
|
||||||
Form = formBinding{}
|
Form = formBinding{}
|
||||||
|
MultipartForm = MultipartFormBinding{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func Default(method, contentType string) Binding {
|
func Default(method, contentType string) Binding {
|
||||||
@ -42,6 +43,8 @@ func Default(method, contentType string) Binding {
|
|||||||
return JSON
|
return JSON
|
||||||
case MIMEXML, MIMEXML2:
|
case MIMEXML, MIMEXML2:
|
||||||
return XML
|
return XML
|
||||||
|
case MIMEMultipartPOSTForm:
|
||||||
|
return MultipartForm
|
||||||
default:
|
default:
|
||||||
return Form
|
return Form
|
||||||
}
|
}
|
||||||
|
25
binding/form_multipart.go
Normal file
25
binding/form_multipart.go
Normal 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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user