Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set filename in Content-Disposition if filename=x is passed in URI query #4177

Merged
merged 1 commit into from
Aug 21, 2018

Conversation

Voker57
Copy link
Contributor

@Voker57 Voker57 commented Aug 28, 2017

Helps with referring to hashes by specific filename, eliminated unixfs node need for that

Example: http://ipfs.io/ipfs/Qmfoobar -- downloads Qmfoobar.zip (if mime was detected by first block)
http://ipfs.io/ipfs/Qmfoobar?filename=stuff.zip -- downloads stuff.zip

@@ -132,7 +133,7 @@ func (i *gatewayHandler) optionsHandler(w http.ResponseWriter, r *http.Request)
}

func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {

log.Errorf("see me?")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove stray debugging line

@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
url "net/url"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do "net/url" here, the import name will be the same

@crackcomm
Copy link

crackcomm commented Nov 28, 2017

It works for .zip but .pdf or .png will need attachment to download (not inline).

@Voker57
Copy link
Contributor Author

Voker57 commented Nov 28, 2017

That's out of scope of this PR: I just want files that are saved from link to be named properly.

@crackcomm
Copy link

@Voker57 sounds good, I wanted to suggest a download query parameter but only after posting a comment :)

@radfish
Copy link

radfish commented Aug 18, 2018

@lgierth Is this waiting on any more changes? Is there a need for a branch based on MIME type? ('inline' for application/pdf, and 'attachment' for everything else) or is 'inline' ok to pass for all MIME types?

Without this feature linking to files is a big problem (I often specifically do not want wrapping directories, but a direct link). Luckily, for application/pdf, for whatever reason, Firefox seems to grab the filename if you append any query, even any parameter name at all, even verbatim .../hash?foo=XYZ opens in the PDF viewer and the title is set to XYZ and if you press the save button, the name is XYZ. Firefox does this, because the headers are identical between .../hash?foo=XYZ and .../hash. But, for other types, things are bad, no filename in the save dialog.

@Stebalien
Copy link
Member

Is this waiting on any more changes?

Looks like it just dropped through the cracks.

Is there a need for a branch based on MIME type? ('inline' for application/pdf, and 'attachment' for everything else) or is 'inline' ok to pass for all MIME types?

This PR doesn't appear to do any content sniffing, it just sets the appropriate file name.

@Stebalien
Copy link
Member

I've checked and this does not trigger #4025.

@Stebalien Stebalien added the need/review Needs a review label Aug 20, 2018
@Stebalien Stebalien requested a review from a user August 20, 2018 22:26
@Stebalien
Copy link
Member

@lgierth. I'd like to merge this. Any objections?

@Stebalien
Copy link
Member

I've added some documentation here: #5393

@Stebalien Stebalien merged commit fcc96a3 into ipfs:master Aug 21, 2018
@Stebalien Stebalien removed the need/review Needs a review label Aug 21, 2018
@radfish
Copy link

radfish commented Aug 21, 2018 via email

@Stebalien
Copy link
Member

According to the docs, "inline" is the default value so this shouldn't cause a problem. We should probably also add a download=true flag but that's a separate issue.

(thanks for bringing this to our attention, by the way)

lidel added a commit that referenced this pull request Sep 16, 2020
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:
#4177 (comment)
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
Set filename in Content-Disposition if filename=x is passed in URI query

This commit was moved from ipfs/kubo@fcc96a3
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants