question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configurable headers for wagtail documents

See original GitHub issue

It seems Content-Disposition header is always set to ‘attachments’ https://github.com/torchbox/wagtail/blob/v0.8.7/wagtail/wagtaildocs/views/serve.py#L16 which results in browsers prompting users to download the file.

Since modern browsers can easily display PDF files, it would be great if we could make above header configurable.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
ipmbcommented, Sep 13, 2016

Ran into this on a couple of client sites, specifically related to PDF documents not being previewable.

Here’s a workaround that overrides Wagtail’s default document view and redirects to the file URL:

from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from wagtail.wagtaildocs.models import Document


def serve_wagtail_doc(request, document_id, document_filename):
    """
    Replacement for ``wagtail.wagtaildocs.views.serve.serve``
    Wagtail's default document view serves everything as an attachment.
    We'll bounce back to the URL and let the media server serve it.
    """
    doc = get_object_or_404(Document, id=document_id)
    return HttpResponseRedirect(doc.file.url)

Then add this to the top of your urlpatterns (above any wagtail includes):

    # override default wagtail view
    url(r'^documents/(\d+)/(.*)$', [path.to].serve_wagtail_doc,
        name='wagtaildocs_serve'),
2reactions
eyjolfur12commented, Jul 19, 2016

So, any news on this issue. It seams still that pdf’s inserted in RicheText or Stream Fields are served as Content-Type: application/octet-stream and Content-Disposition: attachment; and so downloaded instead of displayed in the browser. Any way yet to affect this behavior?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Settings — Wagtail Documentation 4.1.1 documentation
Customise Wagtail's behaviour when an internal page url is entered in the external link chooser. Possible values for this setting are 'all' ,...
Read more >
Adding custom HTTP headers to Wagtail pages
My issue was that I wasn't aware the module path relates directly to the filename. The following middleware creates and adds the header...
Read more >
Deploying Wagtail — Wagtail 2.2.2 documentation
You are not reading the most recent version of this documentation. v4.1.1 is the ... you'll need to ensure that it is configured...
Read more >
Installation — wagtail-cache 2.2 documentation
Next a cache must be configured in the settings. ... gives you the option to add a custom Cache-Control header via cache_control ,...
Read more >
Wagtail Documentation
Various other settings are available to configure Wagtail's behaviour - see Configuring ... hosted font files that lack a valid header.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found