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

How can I validate a variable of type *multipart.FileHeader? #1238

Open
fullgukbap opened this issue Feb 28, 2024 · 0 comments
Open

How can I validate a variable of type *multipart.FileHeader? #1238

fullgukbap opened this issue Feb 28, 2024 · 0 comments

Comments

@fullgukbap
Copy link

fullgukbap commented Feb 28, 2024

  • [v] I have looked at the documentation here first?
    yes

  • [v] I have looked at the examples provided that may showcase my question here?
    yes

Package version eg. v9, v10:

The package version I used is 10.

Issue, Question or Enhancement:

I have a question. I was writing a REST API server that receives images and stores them in a database.
Convert the client's request to

type ImageCreateRequest struct {
	Name string `form:"name" validate:"required"`
	Description string `form:"description"`
	Image *multipart.FileHeader `form:"image" validate:"required,image"`
}

After receiving this format

	var err error
	if request.Image, err = c.FormFile("image"); err != nil {
		return nil, err
	}

	if err := validator.RequestValidator(request.Image.Filename); err != nil {
		return nil, err
	}

I parsed it this way, and proceeded with the typechecking.
However, interface conversion: error is *validator.InvalidValidationError, not validator.ValidationErrors
(For reference, the framework used gofiber v2.)

I got this error.
I am at a loss to find a solution to this problem.

I would be grateful if you could help me out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant