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

Framework Support #41

Closed
s1rc opened this issue May 2, 2018 · 13 comments
Closed

Framework Support #41

s1rc opened this issue May 2, 2018 · 13 comments

Comments

@s1rc
Copy link

s1rc commented May 2, 2018

Is it possible for this to run on request within a framework, like Laravel?

I want to test this out, however with deployment it would be ideal to have requests handled by our app instead of running a separate server.

@ankitpokhrel
Copy link
Owner

ankitpokhrel commented May 3, 2018

@s1rc I added a rough doc for Laravel integration: https://github.com/ankitpokhrel/tus-php/wiki/Laravel-&-Lumen-Integration

@s1rc
Copy link
Author

s1rc commented May 3, 2018

Thank you, I will give this a try!

@s1rc
Copy link
Author

s1rc commented May 4, 2018

So far so good!

One quick change to your Wiki article. In the route definition, the parameter needs to be optional.

Route::any('/tus/{any?}', function () {
    $response = app('tus-server')->serve();

    return $response->send();
})->where('any', '.*');

@ankitpokhrel
Copy link
Owner

Yes true, thanks :)

@s1rc
Copy link
Author

s1rc commented May 4, 2018

Not sure if I should open a new issue, but do have some follow up questions.

  1. Where are the files stored during upload? In the redis cache?
  2. If using redis cache I cannot resume, if using file cache upload finishes 100% immediately. (both using Uppy)
  3. Is there a completion handler for the server? I want to perform some post upload actions (i.e. add to a media library and remove from the tus upload directory)

@ankitpokhrel
Copy link
Owner

ankitpokhrel commented May 4, 2018

  1. Files are stored in the location you specify while setting up the server. By default, it uses uploads folder in the installation directory.

    ->setUploadDir(storage_path('app/public/uploads')); // upload dir
    
  2. Make sure that tus-server can connect the redis server. You can use REDIS_HOST and REDIS_PORT env to pass redis host and port. You can also directly create and pass redis object.

    // TusServiceProvider.php
    
    $redis = new TusPhp\Cache\RedisStore([
        'host' => '127.0.0.1',
        'port' => '6379',
    ]);
    
    $server = new Server($redis);
    

    if using file cache upload finishes 100% immediately

    I guess you are testing in your local setup. This is related to uppy and the reason is that the progress bar is updated as soon as the first byte is sent to the server. This process is too fast in local and it reaches 100% immediately. If you use actual server this won't happen.

  3. No there isn't but if you are using uppy you can use upload-success event for post upload operations.

@s1rc
Copy link
Author

s1rc commented May 4, 2018

  1. I have it set to the following, and that's where the files end up after completion. I can see when at 100% the files are being copied into that directory, however I can't find the partially uploaded files.
$server
     ->setApiPath('/tus')
     ->setUploadDir(storage_path('tus'));
  1. I can see that redis is working locally, since I am connected to it in a viewer and the records are visible. When I run run with the default files cache the upload is instantly 100% but nothing ends up in the upload dir.

  2. Ok I understand, so I'd have to have Uppy perform another API call and then send the delete event to the Tus server.

@ankitpokhrel
Copy link
Owner

Hi @s1rc,

I just tried in one of my Laravel's installation and it seems to be working fine. I hope you properly setup your tus endpoint for uppy.

const uppy = Uppy.Core({debug: true, autoProceed: false})
    .use(Uppy.Dashboard, {target: '#uppyUploader', inline: true})
    .use(Uppy.Tus, {endpoint: 'http://your.app/tus'}) // tus endpoint
    .run()

Note that if you upload same file again while was successfully uploaded previously it won't get uploaded unless you clear your redis or file cache. File cache is saved in .cache/tus_php.cache.

Flush your cache first and then try uploading some large files and pause it after a while even if uppy shows 100%. You should see partially uploaded file in your uploads dir. Resume it again and when the upload completes, you should be able to see the complete file.

@s1rc
Copy link
Author

s1rc commented May 5, 2018

I set it up exactly as you wrote the Wiki.

I've tried file cache and deleting vendor/ankitpokhrel/tus-php/.cache/tus_php.cache, as well as deleting all records from redis when using redis config.

During upload there are no partially uploaded files in the folder defined at setUploadDir(storage_path('tus'))

I've tried setting the Laravel environment cache to file and redis, no change.

You can see here that pausing and resuming the file just starts over
https://ufile.io/dv2ao

And when a file is at 100% there is a long pause while the file is copied into the folder defined at ``setUploadDir(storage_path('tus'))`
https://ufile.io/ilv9p

@ankitpokhrel
Copy link
Owner

Hi @s1rc,

The progress bar is updated by uppy as soon as the first byte is sent to the server and don't wait for the actual byte to be updated. This process is very quick in local so the progress bar reaches 100% immediately. This won't happen in actual server as there will be lag when sending first byte to the server.

You can see here that pausing and resuming the file just starts over

I see that the file is 2.5gb which will take some time to upload (even partially). Try by uploading small file lets say 50 mb. When the progress bar reaches 100%, wait for 2-3 seconds and pause it, there should be partially uploaded file in your uploads dir.

And when a file is at 100% there is a long pause while the file is copied into the folder

There is long pause because file is now actually being uploaded to the server. Again, this happens only in local because of the way uppy progress bar works.

If you have a test server, I recommend you to check on that and things will be clear for you.

I know this is confusing but it happens only in local and I haven't found a way to fixed that yet. If you can figure out how to fix it that would be a great help. I will try to check with uppy team later.

@s1rc
Copy link
Author

s1rc commented May 7, 2018

@ankitpokhrel thanks for the feedback.

I tested it on a development server on AWS and it does seem to be working better.

@ankitpokhrel
Copy link
Owner

I will try to replicate the issue as soon as I get some time and will get back to you

@ankitpokhrel
Copy link
Owner

Closed in favor of #44

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

No branches or pull requests

2 participants