go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.64k stars 1.31k forks source link

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

Open fullgukbap opened 7 months ago

fullgukbap commented 7 months ago

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.