S3 CDN URL ignored when uploading into posts

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.

2 个赞

令人失望的是,这个问题多年来一直有人报告,却迟迟没有修复。

@DanielMarquard 你是否找到了变通方法,还是被迫将你的 S3 ACL 设置为公开?

我不确定说这是有问题的是否公平,因为更复杂的实现并未得到完全支持。

按文档说明进行的 S3 上传功能正常且行为正确。

@Stephen 这当然可以有多种解读……

在我看来,它在一种情况下使用 CDN URL,而在另一种情况下却不使用,这显得有些“不合理”。此外,它还强制要求一种 AWS 实际上并不推荐的 S3 配置(即对 S3 存储桶使用公共 ACL)。

我虽然刚接触 Discourse 项目,但很乐意为此提交一个 PR。

现在可能值得修复这个问题——AWS 正越来越严肃地通知用户关于公共读取 ACL 的情况。

4 个赞

鉴于我们当前的实现不再包含 IMG 标签,例如:

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

为上述内容应用 CDN 应该相当简单,并且可以节省流量。

@vinothkannans 你能修复一下这个问题吗,让预览使用 CDN URL?

目前预览显示的是:

<img src="//assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/6/6/66ef078b3ef9da9aa1b3356cb21fe22a0d25eaf0.png" alt="image" class="resizable" width="345" height="149">

我们应该显示 CDN URL,如下所示:

<img src="https://d11a6trkgmumsb.cloudfront.net/original/3X/6/6/66ef078b3ef9da9aa1b3356cb21fe22a0d25eaf0.png" alt="image" class="resizable" width="345" height="149">
6 个赞

现已按以下提交修复

6 个赞

此主题在 32 小时后自动关闭。不再允许新回复。

继续讨论 上传到帖子时忽略 S3 CDN 网址

看起来这个问题又出现了,我可以在 meta 上复现。

3 个赞

我们可以检查一下这个吗 @vinothkannans@falco

3 个赞

根据最近的变更,我们现在直接从初始上传请求中获取上传文件的 URL。此前,我们从 /uploads/lookup-urls.json 端点获取该 URL。此提交应能修复该问题。

5 个赞

看起来这个修复不适用于自定义表情符号的预览,例如 :allthethings:

4 个赞

这也缺少附件,例如数据导出或任何文件附件。这些仍然来自 S3。

我可以修复这个问题!

3 个赞