Again, I want to clarify the file does arrive in the browser, but I want
to ensure the "file->save..." dialog appears in the web browser when
it arrives. I found some older code I wrote a couple of years ago that was behaving as expected:
w.Header().Set("Content-Disposition", "attachment; filename=" + myBasePdf + ".pdf")
http.ServeFile(w, req, myGenPdfFileName)
I acknowledge when I wrote this email I made a typo, but in my code I do have the Itoa correctly.
w.Header().Set("Content-Length", strconv.Itoa( len(myCmdOutput) ) )
I never used that content-length field because I read somewhere that I shouldn't.
Last night I took a look at iris to see how they do it and found:
https://github.com/kataras/iris/blob/master/context.go#L583err := ctx.ServeFile(filename, false) |
ctx.
RequestCtx.
Response.
Header.
Set(contentDisposition,
"attachment;filename="+destinationName)
I am scratching my head since the header set content-disposition is happening after the ServeFile which is different from what all the docs and what I am used to seeing. It seems calling these functions are order-independant. When does the connection actually send the file over the connection?
I believe the Iris send file also provides what I want as expected behaviour, but I haven't
tried it yet.