Inline Attachments on Pages #4278

Closed
opened 2026-02-05 08:24:50 +03:00 by OVERLORD · 2 comments
Owner

Originally created by @paigejulianne on GitHub (Oct 27, 2023).

Describe the feature you'd like

I want the ability to attach a PDF or other document to a wiki page, and then use HTML code (including IFRAMES) to get that attachment to display inline on the page.

Describe the benefits this would bring to existing BookStack users

Would make it much easier to maintain content this way.

Can the goal of this request already be achieved via other means?

I hacked the getHeaders() method in app/Http/DownloadResponseFactory.php to support PDF files the following way. However, it would be helpful if the original MIME type was stored in the attachments table in the database to eliminate the need to have multiple switch statements to return the proper MIME type depending on the attachment file type.


Modified function:

protected function getHeaders(string $fileName, string $mime = 'application/octet-stream'): array
{
// $disposition = ($mime === 'application/octet-stream') ? 'attachment' : 'inline';
$disposition = 'inline';
$downloadName = str_replace('"', '', $fileName);

    switch(substr($downloadName,-3)) {
            case "pdf":
                    $mime = 'application/pdf';
                    break;
    }


    return [
        'Content-Type'           => $mime,
        'Content-Disposition'    => "{$disposition}; filename=\"{$downloadName}\"",
        // 'X-Content-Type-Options' => 'nosniff',
    ];
}

Have you searched for an existing open/closed issue?

  • I have searched for existing issues and none cover my fundamental request

How long have you been using BookStack?

3 months to 1 year

Additional context

No response

Originally created by @paigejulianne on GitHub (Oct 27, 2023). ### Describe the feature you'd like I want the ability to attach a PDF or other document to a wiki page, and then use HTML code (including IFRAMES) to get that attachment to display inline on the page. ### Describe the benefits this would bring to existing BookStack users Would make it much easier to maintain content this way. ### Can the goal of this request already be achieved via other means? I hacked the _getHeaders()_ method in **app/Http/DownloadResponseFactory.php** to support PDF files the following way. However, it would be helpful if the original MIME type was stored in the attachments table in the database to eliminate the need to have multiple switch statements to return the proper MIME type depending on the attachment file type. ---------- Modified function: protected function getHeaders(string $fileName, string $mime = 'application/octet-stream'): array { // $disposition = ($mime === 'application/octet-stream') ? 'attachment' : 'inline'; $disposition = 'inline'; $downloadName = str_replace('"', '', $fileName); switch(substr($downloadName,-3)) { case "pdf": $mime = 'application/pdf'; break; } return [ 'Content-Type' => $mime, 'Content-Disposition' => "{$disposition}; filename=\"{$downloadName}\"", // 'X-Content-Type-Options' => 'nosniff', ]; } ### Have you searched for an existing open/closed issue? - [X] I have searched for existing issues and none cover my fundamental request ### How long have you been using BookStack? 3 months to 1 year ### Additional context _No response_
OVERLORD added the 🔨 Feature Request label 2026-02-05 08:24:50 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Oct 27, 2023):

Hi @paigejulianne,

We have this kind of functionality already built-in. Attachments can be served inline with a mime-type when using the dropdown on the attachment item (when viewing a page) then selecting to open in a new tab. Alternatively you can just add ?open=true to the attachment URL.

image

You can find this functionality close to where you were applying modifications, in DownloadResponseFactory->streamedInline

There is an allow-list for content types that are provided via this mechanism (see here) but most common types you'll want to use for this kind of use will be in there.

@ssddanbrown commented on GitHub (Oct 27, 2023): Hi @paigejulianne, We have this kind of functionality already built-in. Attachments can be served inline with a mime-type when using the dropdown on the attachment item (when viewing a page) then selecting to open in a new tab. Alternatively you can just add `?open=true` to the attachment URL. ![image](https://github.com/BookStackApp/BookStack/assets/8343178/f214bfea-3282-498f-a8c6-2218edb5d569) You can find this functionality close to where you were applying modifications, in `DownloadResponseFactory->streamedInline` There is an allow-list for content types that are provided via this mechanism ([see here](https://github.com/BookStackApp/BookStack/blob/abc283fc64b7ed3e79f5e499f934130b6146a02b/app/Util/WebSafeMimeSniffer.php)) but most common types you'll want to use for this kind of use will be in there.
Author
Owner

@paigejulianne commented on GitHub (Oct 27, 2023):

Cool beans, thanks for the info. I'll be closing this out and moving along now...

@paigejulianne commented on GitHub (Oct 27, 2023): Cool beans, thanks for the info. I'll be closing this out and moving along now...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#4278