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-To: FormFile in Bind Object? #1298

Closed
iamnande opened this issue Mar 27, 2018 · 2 comments
Closed

How-To: FormFile in Bind Object? #1298

iamnande opened this issue Mar 27, 2018 · 2 comments

Comments

@iamnande
Copy link

Hello there!

I'm trying to figure out if there's a way to simplify an upload handler by including the form file in with the bind object.

type UploadRequest struct {
  Image       interface{} `form:"image" binding:"required"`
  Description string      `form:"description" binding:"required"`
  Owner       string      `form:"owner" binding:"required"`
}

func HandleUpload(c *gin.Context) {

  req := new(UploadRequest)
  if err := c.ShouldBind(req); err != nil {
    // fail brilliantly
  }
  // do wonderful upload-y type things

}

However, when CURLing an image up I receive a binding error:

$ curl -F 'description=super cool thing' -F 'owner=rbalboa27' -F 'image=@/path/to/image.iso' http://localhost:8000/api/image/v1.0/upload
bailing: Key: 'UploadRequest.Image' Error:Field validation for 'Image' failed on the 'required' tag

I've tried a few variations to try and "sniff" the type of UploadRequest.Image to no avail.

Is this type of thing supported/a feature within Gin?

@thinkerou
Copy link
Member

Maybe #1264

@iamnande
Copy link
Author

@thinkerou I'll close this and follow #1264. thanks!

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

2 participants