Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

上传文件时无法返回信息 #23

Open
easygoto opened this issue Dec 19, 2023 · 0 comments
Open

上传文件时无法返回信息 #23

easygoto opened this issue Dec 19, 2023 · 0 comments

Comments

@easygoto
Copy link

easygoto commented Dec 19, 2023

你好,我用了这个中间件,在上传大文件的时候会在服务端报错,客户端收不到任何信息

package main

import (
	"net/http"

	limits "github.com/gin-contrib/size"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	r.Use(limits.RequestSizeLimiter(10))
	r.POST("/", handler)
	_ = r.Run(":8080")
}

func handler(ctx *gin.Context) {
	if file, err := ctx.FormFile("file"); err != nil {
		ctx.JSON(http.StatusOK, gin.H{"msg": "fail: " + err.Error()})
	} else {
		ctx.JSON(http.StatusOK, gin.H{"msg": "ok: " + file.Filename})
	}
}

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant