package main
import (
"fmt"
"github.com/gin-gonic/gin"
_ "github.com/jinzhu/gorm/dialects/mysql"
"log"
"net/http"
)
func main() {
router := gin.Default()
// 为 mutipart 表单 设置一个较低的内存限制(默认是 32 MiB)
router.MaxMultipartMemory = 1
router.POST("/oneFileUpload",oneFileUpload )
router.POST("/twoFileUpload",twoFileUpload )
router.Run(":3000")
}
func twoFileUpload(c *gin.Context){
form,_ := c.MultipartForm()
files := form.File["file[]"]
for _,file := range files {
log.Println(file.Filename)
}
c.String(http.StatusOK,fmt.Sprint("'%s' uploaded"),len(files))
}
func oneFileUpload(c *gin.Context){
file,_ := c.FormFile("file")
log.Println(file.Filename)
c.String(http.StatusOK,fmt.Sprint("'%s' uploaded"),file.Filename)
}
GO 语言 gin 第3篇 实现 单文件,多文件 上传
最新推荐文章于 2024-09-21 00:15:39 发布