增加form-data解析

This commit is contained in:
白茶清欢 2021-09-15 14:58:56 +08:00
parent c52df773ac
commit a6a12b1b55

View File

@ -10,12 +10,11 @@ package request
import ( import (
"encoding/json" "encoding/json"
"io" "io"
"mime/multipart"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
"git.zhangdeman.cn/zhangdeman/gopkg/util"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -187,15 +186,17 @@ func ParsePostRequestForFormData(ctx *gin.Context) (map[string]interface{}, erro
var ( var (
err error err error
result map[string]interface{} 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 return make(map[string]interface{}), err
} }
if err = ctx.Request.ParseForm(); nil != err {
return make(map[string]interface{}), err result = make(map[string]interface{})
} for k, v := range tmp.Value {
if err = util.JSONUnmarshalWithNumberForIOReader(ctx.Request.Body, &result); nil != err { result[k] = v
return make(map[string]interface{}), err
} }
return result, nil return result, nil
} }