From a6a12b1b552fad65c2608e32498124104d3f7140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 15 Sep 2021 14:58:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0form-data=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gin/request/util.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gin/request/util.go b/gin/request/util.go index 60460e0..48b5f02 100644 --- a/gin/request/util.go +++ b/gin/request/util.go @@ -10,12 +10,11 @@ package request import ( "encoding/json" "io" + "mime/multipart" "net/http" "net/url" "strings" - "git.zhangdeman.cn/zhangdeman/gopkg/util" - "github.com/gin-gonic/gin" ) @@ -187,15 +186,17 @@ func ParsePostRequestForFormData(ctx *gin.Context) (map[string]interface{}, erro var ( err error result map[string]interface{} + tmp *multipart.Form ) - if err = ctx.Request.ParseMultipartForm(32 << 20); nil != err { + + if tmp, err = ctx.MultipartForm(); nil != err { return make(map[string]interface{}), err } - if err = ctx.Request.ParseForm(); nil != err { - return make(map[string]interface{}), err - } - if err = util.JSONUnmarshalWithNumberForIOReader(ctx.Request.Body, &result); nil != err { - return make(map[string]interface{}), err + + result = make(map[string]interface{}) + for k, v := range tmp.Value { + result[k] = v } + return result, nil }