我想创建一个 api 来在我的 go-gin 应用程序中上传图像。这是我当前的 api 代码:
func (s *Service) ImageCreate(c *gin.Context) {
token := c.MustGet(tokenKey).(*models.Token)
now := time.Now()
file, err := c.FormFile("file")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "01> " + err.Error()})
return
}
}
当我从浏览器调用我的应用程序时,它返回此错误:
{"error":"01u003e invalid URL escape "%$\xf4""}
在邮递员 api 中,它可以正常工作。怎么了?如何为浏览器修复它?
不要使用 Postman。
curl -X POST http://localhost:8080/server-image/upload-file -F "file=@/Users/shikuanxu/Downloads/images/course-outline.png" -H "Content-Type: multipart/form-data"
再试一次