I add file to my API and got invalid character '-' in numeric literal in POST API

huangapple go评论79阅读模式
英文:

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

huangapple
  • 本文由 发表于 2022年5月14日 00:44:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/72232907.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定