代码
func main() {
r := gin.Default()
r.GET("/download", func(c *gin.Context) {
//fileName := "11.text"
fileName := "__UNI__9D9D531__20220422141746.apk"
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", fileName)) //fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Type", "application/octet-stream")
c.File("./static/" + fileName)
})
// Listen and Server in 0.0.0.0:8080
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}
文件目录