diff options
author | Corey Hulen <corey@hulen.com> | 2015-09-25 14:28:13 -0700 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2015-09-25 14:28:13 -0700 |
commit | edd99e243f0688a1bae2613558438d78e492c9b8 (patch) | |
tree | 1ee8b624f209ff921e96b3abf2ae252bd6ad1a6b /api | |
parent | 63960fae0996c3dc09a55efab9654893190460d9 (diff) | |
parent | 8b63ca03ea3b1f005ee3b8ec516f30fd035d52cb (diff) | |
download | chat-edd99e243f0688a1bae2613558438d78e492c9b8.tar.gz chat-edd99e243f0688a1bae2613558438d78e492c9b8.tar.bz2 chat-edd99e243f0688a1bae2613558438d78e492c9b8.zip |
Merge pull request #812 from hmhealey/plt256
PLT-256 Add headers to getFile api calls from IE/Edge to trigger file download
Diffstat (limited to 'api')
-rw-r--r-- | api/file.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/api/file.go b/api/file.go index 694fc734c..1cb05e81b 100644 --- a/api/file.go +++ b/api/file.go @@ -13,6 +13,7 @@ import ( "github.com/gorilla/mux" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" + "github.com/mssola/user_agent" "github.com/nfnt/resize" "github.com/rwcarlsen/goexif/exif" _ "golang.org/x/image/bmp" @@ -426,6 +427,19 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "max-age=2592000, public") w.Header().Set("Content-Length", strconv.Itoa(len(f))) w.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(filename))) + + // attach extra headers to trigger a download on IE and Edge + ua := user_agent.New(r.UserAgent()) + bname, _ := ua.Browser() + + if bname == "Edge" || bname == "Internet Explorer" { + // trim off anything before the final / so we just get the file's name + parts := strings.Split(filename, "/") + + w.Header().Set("Content-Type", "application/octet-stream") + w.Header().Set("Content-Disposition", "attachment;filename=\""+parts[len(parts)-1]+"\"") + } + w.Write(f) } |