I use Gin to create a HTTP server and I want to give a dynamically generated zip archive to the user.
Theoretically I could first generate a zip file on a file system and then serve it. But that is really a bad way (to wait 5 mins before starting download). I want start giving it to a user immediately and push content as it is generated.
I've found DataFromReader (example) but ContentLength is not known until archive is done.
func DownloadEndpoint(c *gin.Context) {
...
c.DataFromReader(
http.StatusOK,
ContentLength,
ContentType,
Body,
map[string]string{
"Content-Disposition": "attachment; filename=\"archive.zip\""),
},
)
}
How can I do that?