今日已更新 344 条资讯 | 累计 20814 条内容
关于我们

Stop exposing your S3 bucket URLs. a dead simple image proxy with CDN caching

/u/HolyPad 2026年06月16日 21:13 2 次阅读 来源:Reddit r/programming

How I replaced all the ugly S3 URLs on my Laravel blog with clean /storage/media/... and /storage/og-images/... paths. The setup: Laravel + Octane + Traefik + Cloudflare. Two buckets -- a private one for uploaded media and a public one for auto-generated OG images. What's in the post: - MediaUrlBusiness helper class that centralizes URL generation (replaced 6+ blade templates of raw Storage::url() calls) - ObjectProxyController that streams files directly from S3 using readStream() + response()->stream() -- no memory buffering - Cache-Control: public, max-age=86400, immutable so Cloudflare caches aggressively - Route setup in routes/static.php with a middleware tweak that doesn't overwrite the proxy's own cache headers One gotcha: Storage::download() and streamDownload() buffer the whole file into memory. Switching to readStream() sends it directly from S3 to the client. submitted by /u/HolyPad [link] [留言]

本文内容来源于互联网,版权归原作者所有
查看原文