ankitpokhrel / tus-php

🚀 A pure PHP server and client for the tus resumable upload protocol v1.0.0
https://tus.io
MIT License
1.4k stars 203 forks source link

Cache dir on env #393

Closed raul3k closed 2 years ago

raul3k commented 2 years ago

Note: Please report any security issues directly to hello [at] ankit.pl

Describe the bug When you access this library with another library, like Vimeo/Laravel, the cache dir is not writable.

{"message":"fopen(/var/www/html/storage/app/public/): failed to open stream: Is a directory","context":{"userId":1,"exception":{"class":"ErrorException","message":"fopen(/var/www/html/storage/app/public/): failed to open stream: Is a directory","code":0,"file":"/var/www/html/vendor/league/flysystem/src/Adapter/Local.php:157"}}

If there was a way to set the cache dir outside vendor would be great, it avoid to set another step in deploy.

In the file:/vendor/ankitpokhrel/tus-php/src/Config/server.php, the file cache config is set to vendor folder, its not configurable. Woul be great to set the cache dir due to server restrictibility.

'file' => [
        'dir' => \dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . '.cache' . DIRECTORY_SEPARATOR,
        'name' => 'tus_php.server.cache',
    ],

To something like this:

´file' => [
        'dir' => getenv('TUS_CACHE_DIR') !== false ? getenv('TUS_CACHE_DIR') :   \dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . '.cache' . DIRECTORY_SEPARATOR,
        'name' => 'tus_php.server.cache',
    ],

To Reproduce Steps to reproduce the behavior:

  1. Setup laravel (with Laravel Nova in my specific case)
  2. Install vimeo/laravel
  3. Try to upload a new video
  4. See error

Expected behavior Video was uploaded successfully. No error due to unwritable cache folder

Additional context What I'm trying to do is to upload a new video to vimeo, using the offical vimeo/laravel package. When I set the owner of the folder to www-data, works fine, but i have to add another deploy step to do so (in the buildspec file to be more exact)

ankitpokhrel commented 2 years ago

Fixed in #396. You can use TUS_CACHE_HOME or XDG_CACHE_HOME env to change cache dir for the file cache. Release pending.

raul3k commented 2 years ago

Thank you @ankitpokhrel