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

Content-Disposition filename ignored somehow #6396

Closed
schmitch opened this issue Aug 28, 2015 · 17 comments
Closed

Content-Disposition filename ignored somehow #6396

schmitch opened this issue Aug 28, 2015 · 17 comments

Comments

@schmitch
Copy link

Hello, currently I render my Browser documents with PDFJS however I have patched the viewer.js to support my Authorization header i just added httpHeaders to paramters before PDFJS.getdocument so nothing special, however PDFJS ignore's my Content-Disposition Header which has a filename=
it always gives me document.pdf

I tested against a CORS version and non cors currently this is my content-disposition:

 Content-Disposition:inline; filename="Angebot_412356.pdf"

Is there a setting that it should use this filename or do I miss something?

Currently it isn't related to #2407 since that will work on save + s.
However on my side either Firefox/Chrome nobody gets the correct content-disposition i tried:

 Content-Disposition: inline; filename=name.pdf
 Content-Disposition: attachment; filename=name.pdf
 Content-Disposition: inline; filename="name.pdf"
 Content-Disposition: attachment; filename="name.pdf"

Also that's the Code I added in viewer.js starting after Line 6373 and the PDFJS line is already there:

 var token = window.localStorage.getItem('token');
 var typ = window.localStorage.getItem('type');
 parameters.httpHeaders = {'Authorization': typ + ' ' + token};
 PDFJS.getDocument(parameters, pdfDataRangeTransport, passwordNeeded,

btw. I could also set the filename by myself, I think of the possibility that I know the filename already.

@schmitch schmitch changed the title Content-Disposition filename ignored somehow?? Content-Disposition filename ignored somehow Aug 28, 2015
@Rob--W
Copy link
Member

Rob--W commented Aug 28, 2015

The Content-Disposition header is currently not parsed.

Patches are welcome! If you're interested:

  • Get the header (search for onHeadersReceived in the src/core directory to find an entry point), and parse it. (note that this parsing is not trivial, e.g. account for special encodings, see other open-source libraries for inspiration).
  • Add an API or use an existing API to communicate the Content-Disposition header from the worker to the main thread.
  • Search for uses of getPDFFileNameFromURL in files in web/, e.g. in web/viewer.js and update it to take the filename in Content-Disposition into account.

@schmitch
Copy link
Author

@Rob--W oh I thought it is cause of some issue's. However if' just appended a &filename="name.pdf" to my url I think that parsing it wouldn't be too trivial for my use case.

@jumbosushi
Copy link

Does this still need work? I would love to make this my first contribution to oss

@Rob--W
Copy link
Member

Rob--W commented Dec 2, 2015

@jumbosushi This still needs work indeed. A few comments back I have described the steps that you can follow to implement this feature. If there's anything unclear, feel free to ask.

@corblanc
Copy link

@Rob--W Would like to give this a try if it's still open.

@Rob--W
Copy link
Member

Rob--W commented Apr 26, 2016

@corblanc This is still open, thanks for giving it a try!

The invitation to ask questions is also still open.

@corblanc
Copy link

@Rob--W Great! Mind if I shoot you an email? Bit new to all of this.

@Rob--W
Copy link
Member

Rob--W commented Apr 26, 2016

@corblanc Go ahead. You can also join us at #pdfjs on irc.mozilla.org if you want to have a conversation.

(edit: irc.mozilla.org, not Freenode)

@david0603
Copy link

Any updates on this? Thanks!

@Koolstr
Copy link

Koolstr commented Jun 7, 2017

This is still an issue, for me at least. Any updates? It's been over a year.

@Maiestas28
Copy link

Hey guys, im new to OSS and this would be my first contribution. The tag looks open. How can i contribute and any guidance is very much needed and much appreciated. Thank you.

@Rob--W
Copy link
Member

Rob--W commented Jan 6, 2018

See #6396 (comment)

I have recently written a simple yet complete Content-Disposition parser, its functionality can be reused: https://github.com/Rob--W/open-in-browser/blob/master/extension/content-disposition.js

@timvandermeij
Copy link
Contributor

Note that there is already a pull request for this issue above (and it's almost finished), hence I would suggest working on another issue instead.

@Maiestas28
Copy link

Maiestas28 commented Jan 6, 2018 via email

@timvandermeij
Copy link
Contributor

Fixed in #9379.

@ddemoss222
Copy link

Has there been regression on this? I am trying to open a base64 pdf from an tag. I set the "download" attribute to the filename which correctly names the PDF on chrome, but with the pdfjs opener in firefox it shows only "document.pdf". If I set the:

 Content-Disposition: attachment; filename=name.pdf
 Content-Disposition: attachment; filename="name.pdf"

The above too is ignored by pdf.js and I just see:

Warning: getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.

Why does pdf.js still ignore the Content-Disposition and download attribute in the a tag. Is this regression? Are there any known workarounds for JSON base64 responses?

@Snuffleupagus
Copy link
Collaborator

@ddemoss222 For future reference: Note that it's always recommended to open a new issue, rather than commenting on one that was closed many years ago, since it's often very easy for comments on old issues to be overlooked/ignored.

Without a runnable test-case it's difficult (or rather impossible) to know for sure, but this is likely fixed by the PR referenced above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.