Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jackFlick's avatar

How to generate DigitalOcean Spaces CDN url on Laravel

I was using the normal file URL of Digital Ocean right now. And figured out that I needed to start using CDN as it loads faster. But when I try to research on how to load it and change ENV configuration it is not working.

I've tried changing the DO_SPACES_ENDPOINT by adding .cdn. , cleared cache and config and reload laravel but nothing happens.

DO_SPACES_KEY=
DO_SPACES_SECRET=
DO_SPACES_ENDPOINT=https://sgp1.cdn.digitaloceanspaces.com
DO_SPACES_REGION=SGP1
DO_SPACES_BUCKET=
CDN_URL=https://sqp1.cdn.digitaloceanspaces.com

I've also tried the following I found on the internet and changed the URL in filesystems

'url' => str_replace(env('DO_SPACES_REGION'),env('DO_SPACES_BUCKET').'.'.env('DO_SPACES_REGION'),str_replace("digitaloceanspaces","cdn.digitaloceanspaces",env('DO_SPACES_ENDPOINT'))),

still not working.

Don't know what else to do on how to make it work.

I'm using this to show the data.

'file' => is_null($this->file) ? null : Storage::temporaryUrl(
                $this->file,
                now()->addMinutes(180)
            ),`

Hope someone can help me on this.

0 likes
0 replies

Please or to participate in this conversation.