# S3 CDN URL ignored when uploading into posts

**URL:** https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898
**Category:** Bug
**Created:** [December 28, 2016, 6:31pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898 "2016-12-28T18:31:44Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![DanielMarquard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danielmarquard/32/74010_2.png) [@DanielMarquard](https://meta.discourse.org/u/DanielMarquard)
#### Post date: [December 28, 2016, 6:31pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/1 "2016-12-28T18:31:44Z")

</div>

All of our traffic goes through CloudFront, and static content is fetched by CloudFront from one of several S3 buckets.

With uploads being sent to S3, Discourse embeds the content with a generic bucket URL despite our having `s3 cdn url` set. Once submitted, posts appear to use the correct URL set in `s3 cdn url`, although this may also be because we have `DISCOURSE_CDN_URL` set as well (both are set to the same URL).

The post preview window references the standard S3 URL seen in the unbaked post, though. This is a problem because we use a private ACL on files uploaded to our Discourse uploads bucket, as content on this bucket should never be accessed outside of CloudFront. The result is a broken image in the preview window.

 ![](https://global.discourse-cdn.com/meta/original/3X/4/d/4d96f8f4542d396e51c81013e7fdbd674912b115.png)

---

<div class="post-metadata">

### Author: ![timkelty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/timkelty/32/158090_2.png) [@timkelty](https://meta.discourse.org/u/timkelty)
#### Post date: [October 9, 2019, 3:58pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/2 "2019-10-09T15:58:21Z")

</div>

Disappointing this has been reported for so many years with no fix.

@DanielMarquard Did you ever figure out a workaround, or were you forced to make your s3 ACL public?

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [October 9, 2019, 4:02pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/3 "2019-10-09T16:02:36Z")

</div>

I’m not sure it’s fair to suggest this is broken, as much as the more complicated implementation isn’t fully supported.

S3 uploads as documented work and behave correctly.

---

<div class="post-metadata">

### Author: ![timkelty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/timkelty/32/158090_2.png) [@timkelty](https://meta.discourse.org/u/timkelty)
#### Post date: [October 9, 2019, 4:07pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/4 "2019-10-09T16:07:06Z")

</div>

@Stephen Certainly up for interpretation…

To me it seems “broken” that it uses the CDN url in one instance and not the other, and it forces an S3 configuration that AWS actually recommends against (public ACL for an s3 bucket).

I’m new to the Discourse project in general, but can certainly work on a PR.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [October 9, 2019, 4:59pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/5 "2019-10-09T16:59:24Z")

</div>

This may be worth fixing now - AWS is getting more serious about informing people of public read ACLs.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 14, 2019, 12:24am UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/6 "2019-10-14T00:24:58Z")

</div>

Given our current implementation no longer has an IMG tag eg:

 ![image](https://global.discourse-cdn.com/meta/original/3X/6/6/66ef078b3ef9da9aa1b3356cb21fe22a0d25eaf0.png)

`![image|690x298,50%](upload://eGAOR4Xy4aRM2lwPIuTokBf60jS.png)`

It should be quite easy to apply a CDN to the above and it saves traffic.

@vinothkannans can you fix this up so preview uses the CDN url

Instead of preview showing:

```plaintext
<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/6/6/66ef078b3ef9da9aa1b3356cb21fe22a0d25eaf0.png" alt="image" class="resizable" width="345" height="149">

```

We should show the CDN URL which is this:

```plaintext
<img src="https://global.discourse-cdn.com/meta/original/3X/6/6/66ef078b3ef9da9aa1b3356cb21fe22a0d25eaf0.png" alt="image" class="resizable" width="345" height="149">

```

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [October 14, 2019, 3:40am UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/8 "2019-10-14T03:40:02Z")

</div>

Now it’s fixed as per the below commit

[https://github.com/discourse/discourse/commit/e4fe864c0b7d4d5d1f0cd604829eca81b71bb4ec](https://github.com/discourse/discourse/commit/e4fe864c0b7d4d5d1f0cd604829eca81b71bb4ec)

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [October 15, 2019, 12:30pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/9 "2019-10-15T12:30:10Z")

</div>

This topic was automatically closed after 32 hours. New replies are no longer allowed.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 29, 2020, 8:08pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/10 "2020-06-29T20:08:48Z")

</div>



---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [June 29, 2020, 3:01pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/11 "2020-06-29T15:01:58Z")

</div>

Continuing the discussion from [S3 CDN URL ignored when uploading into posts](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/8):

It seems like this issue has regressed, I can repro here on meta.

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/1/b1a12d8daf83d6beb133ebbc5ca9b3f972c39ca3.png)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 29, 2020, 8:09pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/12 "2020-06-29T20:09:14Z")

</div>

Can we check this @vinothkannans or @falco?

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [July 2, 2020, 1:11am UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/14 "2020-07-02T01:11:53Z")

</div>

As per the recent change, we’re now getting the uploaded file’s URL from the initial upload request itself. Previously, we received it from the `/uploads/lookup-urls.json` endpoint. This commit should fix the issue.

[https://github.com/discourse/discourse/commit/f11363d446c4c6a01a59d192f5f078c813ed1919](https://github.com/discourse/discourse/commit/f11363d446c4c6a01a59d192f5f078c813ed1919)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [August 4, 2020, 4:39pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/15 "2020-08-04T16:39:43Z")

</div>

Looks like this fix [doesn’t cover custom emoji](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets/159787/5) in the preview, for example :allthethings:.

---

<div class="post-metadata">

### Author: ![applebee1558](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@applebee1558](https://meta.discourse.org/u/applebee1558)
#### Post date: [November 10, 2020, 4:28pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/16 "2020-11-10T16:28:31Z")

</div>

This is also missing attachments like data exports or just any file attachment. Those still come from s3.

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [December 3, 2020, 12:18pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/18 "2020-12-03T12:18:09Z")

</div>

I can fix that!

[https://github.com/discourse/discourse/pull/11401](https://github.com/discourse/discourse/pull/11401)

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [December 9, 2020, 7:05pm UTC](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898/19 "2020-12-09T19:05:31Z")

</div>


