diff --git a/binding/form_mapping.go b/binding/form_mapping.go index 80b1d15a..7d6075b4 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -146,6 +146,15 @@ func setByForm(value reflect.Value, field reflect.StructField, form map[string][ if !ok { vs = []string{opt.defaultValue} } + + switch value.Interface().(type) { + case []byte: + if len(vs) > 0 { + value.Set(reflect.ValueOf([]byte(vs[0]))) + return true, nil + } + } + return true, setSlice(vs, value, field) case reflect.Array: if !ok { diff --git a/binding/multipart_form_mapping.go b/binding/multipart_form_mapping.go index f85a1aa6..1b2ad001 100644 --- a/binding/multipart_form_mapping.go +++ b/binding/multipart_form_mapping.go @@ -6,6 +6,7 @@ package binding import ( "errors" + "io/ioutil" "mime/multipart" "net/http" "reflect" @@ -39,6 +40,22 @@ func setByMultipartFormFile(value reflect.Value, field reflect.StructField, file return true, nil } case reflect.Slice: + switch value.Interface().(type) { + case []byte: + fd, err := files[0].Open() + if err != nil { + return false, err + } + defer fd.Close() + c, err := ioutil.ReadAll(fd) + if err != nil { + return false, err + } + + value.Set(reflect.ValueOf(c)) + return true, nil + } + slice := reflect.MakeSlice(value.Type(), len(files), len(files)) isSetted, err = setArrayOfMultipartFormFiles(slice, field, files) if err != nil || !isSetted {