Skip to content

Commit 3dc1cd6

Browse files
clearcodecnzhangmj
andauthored
fix(binding): binding error while not upload file (#3819) (#3820)
Co-authored-by: zhangmj <zhangmj1@dustess.com>
1 parent 9f598a3 commit 3dc1cd6

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

binding/form_mapping.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package binding
77
import (
88
"errors"
99
"fmt"
10+
"mime/multipart"
1011
"reflect"
1112
"strconv"
1213
"strings"
@@ -235,6 +236,8 @@ func setWithProperType(val string, value reflect.Value, field reflect.StructFiel
235236
switch value.Interface().(type) {
236237
case time.Time:
237238
return setTimeField(val, field, value)
239+
case multipart.FileHeader:
240+
return nil
238241
}
239242
return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface())
240243
case reflect.Map:

binding/form_mapping_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package binding
66

77
import (
8+
"mime/multipart"
89
"reflect"
910
"testing"
1011
"time"
@@ -43,6 +44,7 @@ func TestMappingBaseTypes(t *testing.T) {
4344
{"zero value", struct{ F uint }{}, "", uint(0)},
4445
{"zero value", struct{ F bool }{}, "", false},
4546
{"zero value", struct{ F float32 }{}, "", float32(0)},
47+
{"file value", struct{ F *multipart.FileHeader }{}, "", &multipart.FileHeader{}},
4648
} {
4749
tp := reflect.TypeOf(tt.value)
4850
testName := tt.name + ":" + tp.Field(0).Type.String()

0 commit comments

Comments
 (0)