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

flysystem->delete($file) passes incorrect path #477

Closed
digitalpho3nix opened this issue May 5, 2015 · 8 comments
Closed

flysystem->delete($file) passes incorrect path #477

digitalpho3nix opened this issue May 5, 2015 · 8 comments

Comments

@digitalpho3nix
Copy link

Hello! :)

I've come across an issue where the command delete() passes an incorrect parameter to assertPresent().

I'm using league/flysystem-aws-s3-v2 (1.0.1) with adapter aws/aws-sdk-php (2.8.2) and interacting with a standard Amazon S3 bucket, inside a Laravel 5.0.28 app.

I have an image URL which is being retrieved from a database (stored as VARCHAR) which is being retrieved (and stored) correctly. However, when the delete() command is used, one of the leading slashes is omitted...

eg. Image URL: https://s3-ap-southeast-2.amazonaws.com/anonbucket/avatars/1.png is being passed to assertPresent() as https:/s3-ap-southeast-2.amazonaws.com/anonbucket/avatars/1.png

One of the slashes after the https is gone! Logging in my code reveals the correct path is being passed to the delete() function, so something is going wrong in there somewhere....

Could you please advise on how to fix this?

Many thanks :)

@frankdejonge
Copy link
Member

@digitalpho3nix I'm pretty sure this is misconfiguration. Could you share your config and some code to reproduce this?

@digitalpho3nix
Copy link
Author

No worries! :)

Filesystem.php

's3' => [
            'driver' => 's3',
            'key'    => 'SOMESECRETKEY,
            'secret' => 'MYSUPERSECRETKEY',
            'region' => 'ap-southeast-2',
            'bucket' => 'anonbucket',
],

HttpController.php

...
Log::info($user['avatar']); // Logs correct URL
$filesystem->delete($user['avatar']);
...
// Go on to store new image which works as expected

Log.log

[2015-05-05 12:36:33] local.INFO: https://s3-ap-southeast-2.amazonaws.com/anonbucket/avatars/1.png  
[2015-05-05 12:36:33] local.ERROR: exception 'League\Flysystem\FileNotFoundException' with message 'File not found at path: https:/s3-ap-southeast-2.amazonaws.com/anonbucket/avatars/1.png' in /Users/christopherlane/Desktop/Laravel/project/vendor/league/flysystem/src/Filesystem.php:533
Stack trace:
#0 /Users/christopherlane/Desktop/Laravel/project/vendor/league/flysystem/src/Filesystem.php(306): League\Flysystem\Filesystem->assertPresent('https:/s3-ap-so...')
#1 /Users/christopherlane/Desktop/Laravel/project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php(140): League\Flysystem\Filesystem->delete('https://s3-ap-s...')
#2 /Users/christopherlane/Desktop/Laravel/project/app/Http/Controllers/ProfileController.php(86): Illuminate\Filesystem\FilesystemAdapter->delete('https://s3-ap-s...')

@frankdejonge
Copy link
Member

@digitalpho3nix You're using the full url to delete the asset, you should however only use the relative part (from the bucket, avatars/1.png). This causes the error. All the paths in Flysystem are relative to aid better portability.

@digitalpho3nix
Copy link
Author

Well that works perfectly actually, thanks a bunch. I didn't see this tidbit of info in the docs or API initially, but now it seems quite obvious... :(

Thanks for your time :)

@zaak
Copy link

zaak commented May 6, 2015

@frankdejonge maybe it should be stated more clearly in the documentation that path used with Flysystem should be always relative. Looks like it's a frequent issue :)

@frankdejonge
Copy link
Member

@zaak good point 👍

@cjwotbot
Copy link

@frankdejonge So if I want to move files between the different "disks", is there anyway to implement it ?

@frankdejonge
Copy link
Member

@cjwotbot what you can do is use streams for this, the mount manager does this too, the code will be a copy of that actually.

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