echo
echo copied to clipboard
Unknow Type when binding slice of struct in formdata request
Issue Description
can not bind a slice of struct when the request type is formdata
Checklist
- [x] Dependencies installed
- [x] No typos
- [x] 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
Could you please provide a full working example? Please include the code of the server and some request that shows your issue.
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'```
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
The binder has seen some improvments to allow manual binding using the fluent binder or add a customer binder implementation.
See the docs for:
- https://echo.labstack.com/guide/binding/#fluent-binding
- https://echo.labstack.com/guide/binding/#custom-binding