Gin 的上传
直接看官方示例就可以 - https://gin-gonic.com/docs/examples/upload-file/multiple-file/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| func main() { router := gin.Default() router.MaxMultipartMemory = 8 << 20 router.POST("/upload", func(c *gin.Context) { form, _ := c.MultipartForm() files := form.File["upload[]"]
for _, file := range files { log.Println(file.Filename)
c.SaveUploadedFile(file, dst) } c.String(http.StatusOK, fmt.Sprintf("%d files uploaded!", len(files))) }) router.Run(":8080") }
|
Gin 的 下载
一个是静态文件服务 - https://gin-gonic.com/zh-cn/docs/examples/serving-static-files/
另一个是 Github Readme.md - https://github.com/gin-gonic/gin#serving-data-from-file
1 2 3 4 5 6 7 8 9 10 11 12
| func main() { router := gin.Default()
router.GET("/local/file", func(c *gin.Context) { c.File("local/file.go") })
var fs http.FileSystem = router.GET("/fs/file", func(c *gin.Context) { c.FileFromFS("fs/file.go", fs) }) }
|