首页 > 解决方案 > golan-gin api 返回无效的 URL 转义 %

问题描述

我想创建一个用于在我的 go-gin 应用程序中上传图像的 api。这是我当前的 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":"01\u003e invalid URL escape \"%$\\xf4\""}

在邮递员 api 中,它可以正常工作。怎么了?如何为浏览器修复它?

标签: go

解决方案


不要使用邮递员。

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"

再试一次


推荐阅读