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

Storage::disk('s3')->url() autogenerates the url wrong when you use a root path #42136

Closed
victorelec14 opened this issue Apr 26, 2022 · 3 comments

Comments

@victorelec14
Copy link

victorelec14 commented Apr 26, 2022

  • Laravel Version: 9.9.0
  • PHP Version: 8.1.3

Description:

Hi,

It seems that Storage::url() doesn't correctly generate the URL when you use a root path and grabs it as a slash in encoded html.

Without the root path it correctly generates the url.

When I give it the url parameter (with the fixed url) it works but it also adds the slash backwards.

With root path

This added "%5C" for the slash in the url.

// Filesystem.php
's3' => [
            'driver' => 's3',
            'key' => env('S3_ACCESS_KEY_ID'),
            'secret' => env('S3_SECRET_ACCESS_KEY'),
            'region' => env('S3_DEFAULT_REGION', 'eu-central-1'),
            'bucket' => env('S3_BUCKET'),
            'endpoint' => env('S3_ENDPOINT', 'https://s3.xxxxx.com'),
            'root' => 'test',
            //'url' => "https://bucketyyy.s3.xxxxxx.com/",
        ],
>>> Storage::disk('s3')->url('profile-photos/123.jpg')                                                                                                                                                               
=> "https://bucketyyy.s3.xxxxxx.com/test%5Cprofile-photos/123.jpg"
>>> Storage::disk('s3')->path('profile-photos/123.jpg')                                                                                                                                                              
=> "test\profile-photos/123.jpg"

with Root path + url

but if I add the url parameter and pass it directly to it, it will use the url correctly:

// Filesystem.php
's3' => [
            'driver' => 's3',
            'key' => env('S3_ACCESS_KEY_ID'),
            'secret' => env('S3_SECRET_ACCESS_KEY'),
            'region' => env('S3_DEFAULT_REGION', 'eu-central-1'),
            'bucket' => env('S3_BUCKET'),
            'endpoint' => env('S3_ENDPOINT', 'https://s3.xxxxx.com'),
            'root' => 'test',
            'url' => "https://bucketyyy.s3.xxxxxx.com/",
        ],
>>> Storage::disk('s3')->url('profile-photos/123.jpg')                                                                                                                                                               
=> "https://bucketyyy.s3.xxxxxx.com/test\profile-photos/123.jpg"
>>> Storage::disk('s3')->path('profile-photos/123.jpg')                                                                                                                                                              
=> "test\profile-photos/123.jpg"

Without root path and url [OK]

// Filesystem.php
's3' => [
            'driver' => 's3',
            'key' => env('S3_ACCESS_KEY_ID'),
            'secret' => env('S3_SECRET_ACCESS_KEY'),
            'region' => env('S3_DEFAULT_REGION', 'eu-central-1'),
            'bucket' => env('S3_BUCKET'),
            'endpoint' => env('S3_ENDPOINT', 'https://s3.xxxxx.com'),
        ],
>>> Storage::disk('s3')->url('profile-photos/123.jpg')                                                                                                                                                               
=> "https://bucketyyy.s3.xxxxxx.com/profile-photos/123.jpg"
>>> Storage::disk('s3')->path('profile-photos/123.jpg')                                                                                                                                                              
=> "profile-photos/123.jpg"

Thanks!

@driesvints
Copy link
Member

Heya, this isn't a Laravel issue but an AWS SDK issue I think. See #41964 & https://github.com/thephpleague/flysystem-aws-s3-v3/issues/293

@andaril
Copy link

andaril commented Jul 2, 2022

Just had this behaviour with backup package
My config was

        'my-backup' => [
            'driver' => 's3',
            'key' => 'key',
            'secret' => 'key',
            'region' => 'my-1',
            'bucket' => 'bckps',
            'root'   => '/',
            'endpoint' => 'https://example.com',
            'use_path_style_endpoint' => true,
        ],

And I got this nice path generation

dd(\Storage::disk('my-backup')->allFiles('toapp'));
array:34 [▼
  0 => "oapp/2022-03-27-00-15-02.zip"
  1 => "oapp/2022-04-10-00-15-02.zip"
....

as u can see I got path toapp converted to oapp

@incoming-th
Copy link

I know this one is closed but yes I confirm the bug still exist with root set to "/".

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

No branches or pull requests

4 participants