gin路由直接访问
//下载图片
r.GET("/download", func(c *gin.Context) {
c.Header("Content-Type", "application/octet-stream") //换起浏览器得下载
c.Header("Content-Disposition", "attachment;filename="+"test.webp") //设置文件名
c.File("/static/images/one.webp")
})
前后端中
r.GET("/download", func(c *gin.Context) {
c.Header("filename", "xxx.png")//唤起浏览器得下载
c.Header("msg", "返回信息") //设置文件名
c.File("/static/images/one.webp")
})
gin框架学习记录——文件下载
最新推荐文章于 2025-04-22 11:36:19 发布