Skip to content

Commit

Permalink
feat(gateway): ?filename with download=true
Browse files Browse the repository at this point in the history
This implements 'attachment' mode triggered then
?filename parameter is accompanied with &download=true

When Content-Disposition: attachment is detected by a modern browser
it will skip rendering and immediately open the "save as" dialog,
making this useful feature for using IPFS gateway as target of
"Download" links on various websites.

Parameter name was suggested in:
ipfs/kubo#4177 (comment)


This commit was moved from ipfs/kubo@fd01acd
  • Loading branch information
lidel committed Sep 16, 2020
1 parent 61ea246 commit 95182c2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gateway/core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
urlFilename := r.URL.Query().Get("filename")
var name string
if urlFilename != "" {
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename*=UTF-8''%s", url.PathEscape(urlFilename)))
disposition := "inline"
if r.URL.Query().Get("download") == "true" {
disposition = "attachment"
}
w.Header().Set("Content-Disposition", fmt.Sprintf("%s; filename*=UTF-8''%s", disposition, url.PathEscape(urlFilename)))
name = urlFilename
} else {
name = getFilename(urlPath)
Expand Down

0 comments on commit 95182c2

Please sign in to comment.