Exemple #1
0
func (this *GoChromeCastHttpServer) DownloadPlay(c web.C, w http.ResponseWriter, r *http.Request) {
	if params, err := utils.GetParams(r, "id", "file_path"); err != nil {
		w.Header().Set("Content-Type", "application/json")
		r := responses.JsonResponse{}
		r.Method = "DownloadPlay"
		r.Set(nil, err)
		io.WriteString(w, utils.RenderResponse(r))
	} else {
		if sc, display_path, err := this.ds.DownloadPlay(params["id"], params["file_path"]); err != nil {
			w.Header().Set("Content-Type", "application/json")
			r := responses.JsonResponse{}
			r.Method = "DownloadPlay"
			r.Set(nil, err)
			io.WriteString(w, utils.RenderResponse(r))
		} else {
			defer func() {
				if err == nil {
					sc.Close()
				}
			}()
			w.Header().Set("Content-Disposition", "attachment; filename=\""+params["file_path"]+"\"")
			http.ServeContent(w, r, display_path, time.Now(), sc)
		}
	}
}