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-Type", "application/octet-stream")
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#L583
err := ctx.ServeFile(filename, false)
if err != nil {
return err
}
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.
On Thursday, June 23, 2016 at 6:15:16 PM UTC-4, Val wrote:
>
> The commented line seems to have typo strconv.Ito
>
> Maybe the typo prevents proper recompilation, and server goes on with old
> code?
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.