go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

Large files cannot be downloaded in api service.

Open jayecc opened this issue 1 year ago • 2 comments

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

jayecc avatar Jul 11 '22 14:07 jayecc

check your Timeout settings.

kevwan avatar Jul 11 '22 15:07 kevwan

An infinite timeout has been reached, unable to implement streaming mode. It only works for large file downloads.

检查您的设置。Timeout

jayecc avatar Jul 30 '22 09:07 jayecc

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jul 31 '23 01:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Mar 21 '24 01:03 github-actions[bot]