Inline PDF Previews

Tried that, set cors origins to https://xxxxx.s3.us-east-2.amazonaws.com
also set DISCOURSE_ENABLE_CORS: true in the /var/discourse/containers/app.yml
but it’s not working.

1 Like

And you did a ./launcher rebuild app after making changes to app.yml? You might also need to do a browser hard refresh.

2 Likes

Incidentally, you might check the files section of the admin settings to see if you changed settings that are affecting this feature. I also don’t think this feature can be expected to work if you are linking to a PDF hosted on another server. I just tested this on my site and the same PDF served remotely did not show the preview.

Let us know if you find the source of the problem!

Sample markdown of post where remote did not work but uploaded locally did work.

remote: 

[test remote pdf](https://jsoncompare.org/LearningContainer/SampleFiles/PDF/sample-pdf-with-images.pdf)

uploaded locally: 

[sample-pdf-with-images.pdf|attachment](upload://uOJLgHidEXnbqPRn2p6yP10ecQU.pdf) (3.8 MB)

how it looks:

3 Likes

yes. but it didn’t work.

When you enable S3 in Discourse


Then by definition the files are stored on a different domain.
I guess that clears the problem. But I still hope the plugin could be made to support Discourse installations that have S3 enabled.

2 Likes

I am not so familiar with this configuration. Did you follow these instructions?

1 Like

Yes, I have the S3 (and the related “secure media” setting) working for the last couple of years without a problem.
It is only the Inline PDF component that doesn’t work with this setting.

for reference, even setting app.yml like that:

DISCOURSE_ENABLE_CORS: true
DISCOURSE_CORS_ORIGIN: ‘*’

doesn’t help

2 Likes

I ran into this exact problem too, and ended up reversing my S3 uploads just to get this TC to work as it is high value for us:

I really think that as this is official and S3 uploads are encouraged, this should be looked at to see if it can be made to work with S3 somehow. It could be that pdfs are specifically excluded from S3 uploads, but that would suck as some are enormous!

6 Likes

I don’t think anyone would disagree.
I’m guessing it’s about awareness and priorities.
At least regarding the “awareness” perhaps @Johani the OP could add a small note in the topic of this discussion that the inline PDF component doesn’t work with S3 enabled.
It would save others the time of troubleshooting and raise awareness to the issue.

3 Likes

There’s a bit of info about S3 in these posts I’ve fished out of the auto-timer if they’re any help?

7 Likes

A post was merged into an existing topic: Theme-Component Topics project

Yep, that works :smiley:
For reference if anyone else needs this:

  1. go to AWS console buckets https://s3.console.aws.amazon.com/s3/buckets and select the bucket that was used for your Discourse installation

  2. Choose the Permissions tab
    image

  3. Scroll down to “Cross-origin resource sharing (CORS)” and write:

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET"
        ],
        "AllowedOrigins": [
            "https://my-site.com"
        ],
        "ExposeHeaders": []
    }
]

Should look like this:

8 Likes

I wish I’d found that while I was still on S3 uploads!!

Might need to revisit it now. @JammyDodger, I wonder if that stuff should noted on both the S3 and this OP so others don’t trip up on this.

5 Likes

Absolutely. :+1: I was just waiting for some confirmation that it worked before thinking about how best to make an edit. :slightly_smiling_face:

7 Likes

Two ideas, adressing the same problem: the viewport of discourse is rather narrow, so most PDFs are too small to read inline. To adress this, we could

a) make the PDF-iframe resizable? I tried this with CSS already, but no no avail - the underlaying grid seems to be in the way
b) offer a second link “open in new tab” besides the download link? I am very keen on not downloading to much stuff from our forum.

3 Likes

This would be a marked improvement! And shouldn’t be too hard to add I think. Might have a go at a PR for this if I get the space over the next few days.

3 Likes

I think (b) is already provided as an option, eg inline vs open in new tab. Maybe a third option to let users see inline and open in new tab? I like this idea too.

(a) may be difficult given how hard it can be to get things to look right in a post.

3 Likes