S3 CDN URL ignored when uploading into posts

AI-generated summary

A long-standing issue in Discourse is the S3 CDN URL being ignored when uploading into posts. This results in a generic bucket URL being used instead of the custom CDN URL set in s3 cdn url. This problem is particularly significant for users with private ACLs on their S3 buckets, as it causes broken images in the post preview window.

@DanielMarquard first reported the issue, and @timkelty expressed disappointment that it had gone unfixed for so long. @Stephen suggested that the implementation was not fully supported, but @timkelty argued that the behavior was broken and forced users to adopt an S3 configuration that AWS recommends against.

@sam proposed a potential fix, which was implemented by @vinothkannans. However, the issue regressed, as reported by @RGJ. @vinothkannans provided another fix, but it did not cover custom emojis in the preview, as noted by @Falco. Additionally, the fix did not apply to attachments, as pointed out by @applebee1558. A pull request to fix the attachment issue was submitted by @nbianca.

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 „Gefällt mir“

Enttäuschend, dass dies seit vielen Jahren gemeldet wird, ohne dass es eine Lösung gibt.

@DanielMarquard Haben Sie einen Workaround gefunden oder waren Sie gezwungen, Ihre S3-ACL öffentlich zu stellen?

Ich bin mir nicht sicher, ob es fair ist zu behaupten, dass dies defekt ist, da die komplexere Implementierung nur unvollständig unterstützt wird.

S3-Uploads funktionieren wie dokumentiert und verhalten sich korrekt.

@Stephen Auf jeden Fall interpretationsabhängig…

Für mich sieht es „kaputt

Es könnte sich lohnen, dies jetzt zu beheben – AWS nimmt die Benachrichtigung über öffentliche Lese-ACLs immer ernster.

4 „Gefällt mir“

Da unsere aktuelle Implementierung kein IMG-Tag mehr enthält, z. B.:

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

sollte es recht einfach sein, oben genannten Inhalt über ein CDN auszuliefern, was zudem den Datenverkehr reduziert.

@vinothkannans, könntest du das bitte so anpassen, dass die Vorschau die CDN-URL verwendet?

Anstatt dass die Vorschau Folgendes anzeigt:

<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">

sollte die CDN-URL angezeigt werden, und zwar diese:

<img src="https://global.discourse-cdn.com/meta/original/3X/6/6/66ef078b3ef9da9aa1b3356cb21fe22a0d25eaf0.png" alt="image" class="resizable" width="345" height="149">
6 „Gefällt mir“

Jetzt ist es wie im folgenden Commit behoben

6 „Gefällt mir“

Dieses Thema wurde automatisch nach 32 Stunden geschlossen. Neue Antworten sind nicht mehr erlaubt.

Fortsetzung der Diskussion aus S3-CDN-URL wird beim Hochladen in Beiträge ignoriert:

Es scheint, als ob dieses Problem wieder aufgetreten ist. Ich kann es hier auf Meta reproduzieren.

3 „Gefällt mir“

Können wir das überprüfen, @vinothkannans oder @falco?

3 „Gefällt mir“

Gemäß der jüngsten Änderung erhalten wir die URL der hochgeladenen Datei nun direkt aus der ursprünglichen Upload-Anfrage. Zuvor haben wir sie über den Endpunkt /uploads/lookup-urls.json bezogen. Dieser Commit sollte das Problem beheben.

5 „Gefällt mir“

Es sieht so aus, als würde diese Korrektur keine benutzerdefinierten Emojis in der Vorschau abdecken, zum Beispiel :allthethings:.

4 „Gefällt mir“

Auch fehlen Anhänge wie Datenexporte oder beliebige Dateianhänge. Diese stammen weiterhin aus S3.

Das kann ich beheben!

3 „Gefällt mir“