statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Why are S3 assets saved with an absolute url? #2344

Closed madsem closed 5 years ago

madsem commented 5 years ago

I've developed my first site using local asset containers, all entries are saved with their relative paths. So far so good, now I switch the asset containers over to s3, and all of a sudden all assets are saved with absolute urls pointing to my s3 bucket...

That is totally unexpected imho, and also not the way it should be done. IMHO, assets should always only be saved using relative paths, that way one can also easily use any kind of CDN domain.

Statamic tags should then also be smart enough to build the right urls, according to the container settings.

Now I have a bunch of entries saved with relative folder paths, and new ones with fully qualified absolute urls pointing to S3. That creates a lot of issues for me.

I think all assets should always only be saved with relative paths, and absolute urls should be built on the fly according to container settings, that way you can then also use the macro I saw @jackmcdade recommended in other issues about the s3 urls. (I assume at some point Statamic saved relative paths for S3, that would then make sense to use ensure_left: 'http://my-cdn-domain.com/'.)

But if I already have absolute urls saved in my content, this macro won't help me either as it will just add the CDN domain in front of the S3 domain.

Saving hardcoded strings in all of the content, that is pretty much of a dynamic nature is a bad idea. S3 buckets can change at any time, CDN domains can change etc.

Overall it would be much better and also for standardization's sake, to only use relative paths.

jasonvarga commented 5 years ago

Add url: http://your-cdn.com to your asset container

We save absolute urls so you can output them immediately without needing any additional tags for performing lookups. If you have multiple containers but we only save relative urls, it wouldn’t know which container url to prepend.

We’ll reevaluate for v3 since we now associate the field with the field type and will be able to infer the container url.

madsem commented 5 years ago

Gotcha, okay the url: option is already extremely helpful, sadly undocumented ;) Thanks @jasonvarga

madsem commented 5 years ago

Just an FYI: I've tested the url: setting, it works but ignores the path: setting, so that all urls come out broken. Have to append the path to the url that fixes it.

Hope v3 will allow for a more consistent approach with assets.

Thanks again!