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

Scoped filesystem driver not compatible #16

Closed
Askancy opened this issue Oct 28, 2023 · 6 comments
Closed

Scoped filesystem driver not compatible #16

Askancy opened this issue Oct 28, 2023 · 6 comments

Comments

@Askancy
Copy link

Askancy commented Oct 28, 2023

Scopes are not compatible, you get an error that it does not have permission to access the file.

laravel/framework#44105

@rolandstarke
Copy link
Owner

rolandstarke commented Nov 4, 2023

Hey, thanks for the report.

Is the error you are getting like: Source is not allowed. Given path "1.jpg" on disk "test"?

I got the above error when trying it myself with:
\Thumbnail::src('1.jpg', 'test')>url();
It looks like the library needs the leading slash. With the following code it worked:
\Thumbnail::src('/1.jpg', 'test')>url();

I updated the library to support omitting the leading slash. The fix is in v1.0.7.

@Askancy
Copy link
Author

Askancy commented Nov 4, 2023

Thank you for your reply @rolandstarke

I currently have this and it works:
{{ Thumbnail::preset('gallery')->src('bucket/gallery/'.$value->path, 's3')->url(true) }}

to sort it all out I'm implementing filesystems with scope, and here's the scope I'm using:

        's3_gallery' => [
            'driver' => 'scoped', // This is the new scoped driver!
            'disk' => 's3',       // It uses the `s3` disk above
            'prefix' => 'bucket/gallery',
        ],

So here is the new code, I get the error, however::
{{ Thumbnail::preset('gallery')->src($value->path, 's3_gallery')->url(true) }}

Source is not allowed. Given path "2472/mO84aKBl6lpQnxPNDyPt5gltlge.webp" on disk "s3_gallery"

I tried as you say, with the slash in front, but I keep getting the error:

{{ \Thumbnail::preset('gallery')->src($value->path, 's3_gallery')->url(true) }}

I believe that he has problems using the scoped filesystem

@rolandstarke
Copy link
Owner

rolandstarke commented Nov 4, 2023

I believe the issue could be that in config/thumbnail.php you would need to add the new disk as an allowed source. I hope then it works.

    'allowedSources' => [
        // ...
        's3_g' => ['disk' => 's3_gallery', 'path' => '/'], // <-- add the new disk
    ],

@rolandstarke
Copy link
Owner

rolandstarke commented Nov 4, 2023

I was not happy with the fix in v1.0.7. I released v1.0.8. You would need to update your config/thumbnail.php and remove the /. That would allow every file on that disk.

  'allowedSources' => [
       // ...
       's3_g' => ['disk' => 's3_gallery', 'path' => ''], // <-- add the new disk
   ],

@Askancy
Copy link
Author

Askancy commented Nov 4, 2023

Thank you very much, the files are now read correctly. Just a small note though:
I added in thumbnail.php:

in allowedSources
's3_g' => ['disk' => 's3_gallery', 'path' => ''],

s3_g What would it stand for? this parameter when used? in my blade i used:

{{ Thumbnail::preset('gallery')->src($value->path, 's3_gallery')->url() }}

It would be really nice if it read data from filesystems.php instead of having to indicate routes. anyway great job, definitely the best thumbnail package

@rolandstarke
Copy link
Owner

s3_g can be any string you want. You don't need and can't use it anywhere. It's used by the library as a param in the URL. ?s=s3_g. I picked a short name, so that the URL does not get longer than needed.

Thanks for the feedback. Allowing every disk from the filesystems.php would simplify the usage of the library. So that you don't need to fiddle around with the allowedSources settings. I am not sure if users rely on the security to list every disk they want to load images from.

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

2 participants