S3 Uploads - Using CDN for PDFs?

Hi All,

I just enabled S3 uploads on my Discourse instance, configured with a Cloudfront CDN. I just tested uploading an image and a PDF file as attachments into posts and they are correctly uploaded into the S3 bucket. However, inspecting the page where both are shown, I see that the PDF does not use the CDN link, but the image does.

For the image, the img src points to the CDN, which the browser uses to load the thumbnail.

For the PDF file, the link src points to a relative URL (/uploads/short-url/xxxxxxxxxxxxx.pdf), which seems to redirect to the file in my actual S3 bucket (not the CDN).

Is this expected? This is my first time using a CDN, so perhaps one typically doesn’t serve larger files through it? I just want to make sure that I have all my settings correct and working before migrating all older posts to S3.

Thank you!

4 Likes

Interesting observation, something I’ve not noticed before.

I did a couple of tests.

Some existing PDF uploads do link directly to CDN:

Some existing PDF uploads do not use the CDN:

What’s the difference? :thinking:

I don’t know :man_shrugging: I’d need to check more examples.

I tried a quick test by DM’ing myself and a new post, shows /short-url/ as per your details:

Clicking the link then pulls directly from the S3 bucket, again as per your description:

I’m not quite sure why some of our posts do use the CDN and some don’t, but I can replicate some of what you’re seeing.

1 Like

I think that your need to rebake the posts. The ones uploaded before your added the CDN are not automatically updatedmRebake all posts matching a pattern, (it might be easier to just rebake all of them)

1 Like

Thanks @pfaffman

I just rebaked all posts and found no change. After rebaking, I created some test posts again. To re-cap what I’m seeing (and looks like what @Richie sees)

-An image in a post correctly links to the CDN for the image displayed inline in the post.
-For the image however, the “download” link (lower right when viewing the image full size), links to a short-url, which redirects to my S3 bucket (not the CDN)
-For a PDF upload, the link links to a short-url, which redirects to my S3 bucket (not the CDN).

It appears that any time a short-url is used, the CDN is not used in the redirection.

For my Discourse setup, I am using S3 for both uploads and backups. I have not moved all of my existing uploads to S3 yet (will do once I get over this issue). I also do not have secure uploads enabled.

Thanks!

4 Likes

Thanks for reporting this, we will have a look next week and sort out any missing CDN bypasses that are left. We should always where possibly reach to the CDN with the caveat that if you have secure uploads enabled we can not do so easily.

5 Likes

I’ve noticed this with other file uploads as well:

1 Like