From 793d21651b7deb8770b8ea38ca9109cc1fbde148 Mon Sep 17 00:00:00 2001 From: "anatoly@nspcc.ru" Date: Wed, 10 Jun 2020 20:04:27 +0300 Subject: [PATCH] Add filename to save file in the browser --- receive.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/receive.go b/receive.go index 2771bd7..8a714b1 100644 --- a/receive.go +++ b/receive.go @@ -113,6 +113,7 @@ func (a *app) receiveFile(c *fasthttp.RequestCtx) { func receiveObject(c *fasthttp.RequestCtx, cli object.Service_GetClient) error { var ( typ string + content_disp_type string put = c.Request.URI().QueryArgs().GetBool("download") ) @@ -138,9 +139,12 @@ func receiveObject(c *fasthttp.RequestCtx, cli object.Service_GetClient) error { if hdr := obj.Headers[i].GetUserHeader(); hdr != nil { c.Response.Header.Set("x-"+hdr.Key, hdr.Value) - if hdr.Key == object.FilenameHeader && put { + if hdr.Key == object.FilenameHeader { + if put { + content_disp_type = "attachment" + } else { content_disp_type = "inline"} // NOTE: we use path.Base because hdr.Value can be something like `/path/to/filename.ext` - c.Response.Header.Set("Content-Disposition", "attachment; filename="+path.Base(hdr.Value)) + c.Response.Header.Set("Content-Disposition", content_disp_type+"; filename="+path.Base(hdr.Value)) } } }