ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
文件上传 === 单文件上传 ~~~ func main() { app := gin.Default() app.POST("/upload", func(context *gin.Context) { app.MaxMultipartMemory = 100 << 20 // 设置最大上传大小为100M header, _ := context.FormFile("file") path := "./file/" + header.Filename // 上传存储到的地址 fmt.Println(path) err := context.SaveUploadedFile(header, path) if err != nil { fmt.Println(err.Error()) } log.Println(header.Filename," ",header.Size," ",header.Header) context.JSON(200,gin.H{ "fileName":header.Filename, }) }) app.Run(":8085") } ~~~ 多文件上传 ~~~ func main() { app := gin.Default() app.POST("/uploads", func(ctx *gin.Context) { form, _ := ctx.MultipartForm() files := form.File["upload[]"] for _,file := range files { log.Println(file.Filename) ctx.SaveUploadedFile(file,"./file/"+file.Filename) // 文件夹需要向创建 } }) app.Run(":8085") } ~~~