Advertisement
cydside

Gin Download File example

Jan 17th, 2024 (edited)
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.42 KB | None | 0 0
  1. func DownloadLicense(c *gin.Context) {
  2.     content:="Download file here happliy"
  3.     fileName := "hello.txt"
  4.     c.Header("Content-Disposition", "attachment; filename="+fileName)
  5.     c.Header("Content-Type", "application/text/plain")
  6.     c.Header("Accept-Length", fmt.Sprintf("%d", len(content)))
  7.     c.Writer.Write([]byte(content))
  8.     c.JSON(http.StatusOK, gin.H{
  9.         "msg": "Download file successfully",
  10.     })
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement