go-zero
go-zero copied to clipboard
Large files cannot be downloaded in api service.
Describe the bug go-zero api cannot realize file stream download when downloading large files ?
1、go http server
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename=demo.csv")
w.Header().Set("Content-Transfer-Encoding", "binary")
wr := csv.NewWriter(w)
for i := 0; i < 5e10; i++ {
wr.Write([]string{strconv.Itoa(i), time.Now().String()})
wr.Flush()
}
})
http.ListenAndServe(":8888",nil)
}
2、go-zero server
func templateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename=demo.csv")
w.Header().Set("Content-Transfer-Encoding", "binary")
wr := csv.NewWriter(w)
for i := 0; i < 5e10; i++ {
wr.Write([]string{strconv.Itoa(i), time.Now().String()})
wr.Flush()
}
}
}
Environments (please complete the following information):
- OS: darwin/amd64
- go-zero version 1.3.3
- goctl version 1.3.5
@kevwan
check your Timeout
settings.
An infinite timeout has been reached, unable to implement streaming mode. It only works for large file downloads.
检查您的设置。
Timeout
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.