Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Support custom URLs for AWS storage #22037

Merged
merged 1 commit into from
Nov 10, 2017

Conversation

nesk
Copy link
Contributor

@nesk nesk commented Nov 9, 2017

AWS allows developers to customize their file URLs through DNS configuration. However, Laravel doesn't provide anything to generate customized file URLs for the s3 driver.

This pull-request fixes that by allowing users to define a url property in their configuration, just like the local driver:

's3' => [
    'driver' => 's3',
    'url' => 'https://files.example.org',
    'key' => env('AWS_KEY'),
    'secret' => env('AWS_SECRET'),
    'region' => env('AWS_REGION'),
    'bucket' => env('AWS_BUCKET'),
],
Storage::url('my/image.png'); // Returns: https://files.example.org/my/image.png

@GrahamCampbell GrahamCampbell changed the title Support custom URLs for AWS storage [5.5] Support custom URLs for AWS storage Nov 9, 2017
@taylorotwell taylorotwell merged commit 7a32247 into laravel:5.5 Nov 10, 2017
@tillkruss
Copy link
Contributor

tillkruss commented Nov 18, 2017

@nesk: This is great, but it's ignoring the root (path prefix) entirely.

's3' => [
    'driver' => 's3',
    'url' => 'https://files.example.org',
    'root' => 'footer',
],

This call:

Storage::url('my/image.png');

Returns:

https://files.example.org/my/image.png

But should return:

https://files.example.org/foobar/my/image.png

A simple fix is adding the root to the URL, but that's getting unreadable:

's3' => [
    'root' => env('S3_PREFIX', '_' . env('APP_ENV') . '/'),
    'url' => env('S3_URL', 'https://static.foxy.co') . env('S3_PREFIX', '_' . env('APP_ENV') . '/'),
]

What do you think about adding the root to the URL generation as well? That's the default behaviour when no url is set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants