Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST 请求中,一个 key 包含多个上传文件时,除了第一个文件,其他文件被丢弃,导致 BindSafeData 行为非预期。 #227

Open
hwbrzzl opened this issue Aug 7, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@hwbrzzl
Copy link

hwbrzzl commented Aug 7, 2023

System (please complete the following information):

  • OS: macOS
  • GO Version: 1.18
  • Pkg Version: 1.5.1

Describe the bug

POST 请求中,一个 key 包含多个上传文件时,除了第一个文件,其他文件被丢弃。导致 BindSafeData 只能绑定 File *multipart.FileHeader 类型,而无法绑定 File []*multipart.FileHeader 类型。

To Reproduce

type UserForm struct {
	Name string                  `validate:"required"`
	File []*multipart.FileHeader `validate:"required"`
}

data, err := validate.FromRequest(ctx.Request().Origin())
if err != nil {
	panic(err)
}

v := data.Create()
v.AddRule("name", "required")
v.AddRule("file", "required")

if v.Validate() { // validate ok
	// safeData := v.SafeData()
	userForm := &UserForm{}
	if err := v.BindSafeData(userForm); err != nil {
		panic(err)
	}

	// do something ...
	fmt.Println(userForm.File)
} else {
	fmt.Println(v.Errors)       // all error messages
	fmt.Println(v.Errors.One()) // returns a random error message text
}
curl --location '127.0.0.1:3000' \
--form 'name="test"' \
--form 'file=@"1.pdf"' \
--form 'file=@"2.pdf"'

Expected behavior

BindSafeData 支持绑定 File []*multipart.FileHeader 类型。

Screenshots

image image

Additional context

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants