golan-gin api返回无效的URL转义%

I want to create an api for uploading images in my go-gin application. This is my current api code :

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
    }
}

When I call my application from the browser it returns this error:

{"error":"01\u003e invalid URL escape \"%$\\xf4\""}

In postman api it's working without error. What is wrong? How I can fix it for the browser?

1个回答



不要使用邮递员。</ p>

  curl -X POST http:// 本地主机:8080 /服务器图像/上传文件-F“ file=@/Users/shikuanxu/Downloads/images/course-outline.png” -H“内容类型:multipart / form-data” 
</ code > </ pre>

重试</ p>
</ div>

展开原文

原文

Don't use 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"

Try again

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问