Hello,
I am using Storage class for getting file url like this;
Storage::disk('doSpaces')->url('uploads/file/'.$this->exampleAttribute);
//This gives : mybucketname.ams3.digitaloceanspaces.com/uploads/file/1546429522.jpg
But I dont want orginal file url, I wanna CDN file url like this ;
mybucketname.ams3.cdn.digitaloceanspaces.com/uploads/file/1546429522.jpg
I prefer clean code instead of string manipulation
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $100 of credit to try our products over 60 days!
I know you said no string manipulation but i currently have the same problem and the only clean way I solved it for my self is to put it in a method:
But I also hope for a cleaner code, hope this helps as a quick fix for now
or you can also edit the url attribute in the filesystem config like this
its a bit messy but does the job also this way its stored in the cache
@fatmabensoy @omartuffaha so as you have the spaces registered in the config/filesystem.php, where you specify your endpoint? (if it allows CDN. Currently SFO2 and NYC3 I think, I’d verify)
I just changed my endpoint in my .env file to the following and it serves it all as CDN without any manipulation
that made them all automatically serve up as {spacename].sfo2.cdn.digitalocean.com/filename.jpg
Hope this helps!