Skip to content

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

Open
@easygoto

Description

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions