杜松子酒的web框架限制上传文件大小不起作用

i run the gin example about file upload , this repo is from https://github.com/gin-gonic/examples/tree/5898505356e9064c49abb075eae89596a3c5cd67/upload-file/single. when i change is limit

    router.MaxMultipartMemory = 1 // 8 MiB

but not woking for upload big file, anyone know this.

package main

import (
    "fmt"
    "net/http"

    "github.com/gin-gonic/gin"
)

func main() {

    router := gin.Default()
    // Set a lower memory limit for multipart forms (default is 32 MiB)
    router.MaxMultipartMemory = 1 // 8 MiB
    fmt.Println(router.MaxMultipartMemory)

    router.Static("/", "./public")
    router.POST("/upload", func(c *gin.Context) {
        ct := c.Request.Header.Get("Content-Type")
        fmt.Println(ct)
        name := c.PostForm("name")
        email := c.PostForm("email")
        // Source
        file, err := c.FormFile("file")
        if err != nil {
            c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
            return
        }

        if err := c.SaveUploadedFile(file, file.Filename); err != nil {
            c.String(http.StatusBadRequest, fmt.Sprintf("upload file err: %s", err.Error()))
            return
        }

        c.String(http.StatusOK, fmt.Sprintf("File %s uploaded successfully with fields name=%s and email=%s.", file.Filename, name, email))
    })
    router.Run(":8080")
}

i expect when file size bigger than limit ,there should be a error.

update

misunderstand , the MaxMultipartMemory just limt the memory, not for file upload file size , even file size is more big than this , will write to temp file.

as comment, code

  router.MaxMultipartMemory = 1 // 8 MiB

just limit program can use how much memory when upload file, not limit upload file size.