Download File
package main
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/download", Download)
r.Run(":5000")
}
func Download(ctx *gin.Context) {
filename, _ := ctx.GetQuery("file")
if filename == "" {
ctx.String(http.StatusBadRequest, "invalid requested file")
}
ctx.Header("content-disposition", "attachment;filename=\""+filename+"\"")
ctx.File(fmt.Sprintf("./files/%s", filename))
ctx.String(http.StatusOK, "Downloaded")
}
Last updated
