英文:
I add file to my API and got invalid character '-' in numeric literal in POST API
问题
我知道这段代码需要在API中发送JSON而不是表单数据。
err := ctx.ShouldBindJSON(&modelAdd)
if err != nil {
return err
}
但是我需要添加文件,是否有类似于ShouldBindJSON但用于FormData的方法?
英文:
I know this code need to send a JSON instead of form data in the API
err := ctx.ShouldBindJSON(&modelAdd)
if err != nil {
return err
}
But I need to add file, is there anything like ShouldBindJSON but for FormData?
答案1
得分: 2
你可以使用ShouldBind
来获取表单数据,就像文档中所说的那样。
https://github.com/gin-gonic/gin#model-binding-and-validation
英文:
You can use ShouldBind
to get data from form data as the documentation says
https://github.com/gin-gonic/gin#model-binding-and-validation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论