Skip to content

Unknow Type when binding slice of struct in formdata request #1673

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

Closed
3 tasks done
bashayerAlsalman opened this issue Nov 8, 2020 · 4 comments
Closed
3 tasks done

Comments

@bashayerAlsalman
Copy link

bashayerAlsalman commented Nov 8, 2020

Issue Description

can not bind a slice of struct when the request type is formdata

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

Bind the formdata into the struct

Actual behaviour

Dose not bind formdata request and returns unknown type //err := c.Bind(s)

Steps to reproduce

when sending request

Working code to debug

type request struct {
     id                uint          `form:"id" json:"id"`
     Products   []product `form:"products"`
 }

 type product struct {
     Name          string      `form:"name"`
     Quantity      int           `form:"quantity"`
    Price              float32  `form:"price"`
}

Version/commit

@pafuent
Copy link
Contributor

pafuent commented Nov 10, 2020

Could you please provide a full working example?
Please include the code of the server and some request that shows your issue.

@bashayerAlsalman
Copy link
Author

bashayerAlsalman commented Nov 10, 2020

Could you please provide a full working example?
Please include the code of the server and some request that shows your issue.

Thank you for your response, please find this repo contains a running example
https://github.com/bashayerAlsalman/formdata-with-struct-slice/tree/main

You may use this curl request to reproduce the issue

--header 'Accept-Encoding: multipart/form-data' \
--header 'Accept-Language: en' \
--header 'Cookie: JSESSIONID=05A66C75245B02ABE29D6B4C3715DCD9' \
--form 'id=123' \
--form 'products=[{"name":"tea", "price":12, "quantity":44}]' \
--form 'file=@/Users/imgs.png'```

@pafuent
Copy link
Contributor

pafuent commented Nov 11, 2020

Thanks for the example. It help me to understand your needs. Sadly the current implementation of the Echo DefaultBinder doesn't support your use case.
Also, you can check #1644

@lammel
Copy link
Contributor

lammel commented Dec 2, 2022

The binder has seen some improvments to allow manual binding using the fluent binder or add a customer binder implementation.

See the docs for:

@lammel lammel closed this as completed Dec 2, 2022
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

3 participants