forked from TrueCloudLab/frostfs-http-gw
Add filename to save file in the browser
This commit is contained in:
parent
799d391508
commit
793d21651b
1 changed files with 6 additions and 2 deletions
|
@ -113,6 +113,7 @@ func (a *app) receiveFile(c *fasthttp.RequestCtx) {
|
||||||
func receiveObject(c *fasthttp.RequestCtx, cli object.Service_GetClient) error {
|
func receiveObject(c *fasthttp.RequestCtx, cli object.Service_GetClient) error {
|
||||||
var (
|
var (
|
||||||
typ string
|
typ string
|
||||||
|
content_disp_type string
|
||||||
put = c.Request.URI().QueryArgs().GetBool("download")
|
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 {
|
if hdr := obj.Headers[i].GetUserHeader(); hdr != nil {
|
||||||
c.Response.Header.Set("x-"+hdr.Key, hdr.Value)
|
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`
|
// 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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue