增加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 (
"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
}