pionl / laravel-chunk-upload

The basic implementation for chunk upload with multiple providers support like jQuery-file-upload, pupload, DropZone and resumable.js
MIT License
602 stars 167 forks source link

$fileReceived->isFinished() is never called when uploading the file from a different site #158

Open tato-rj opened 1 year ago

tato-rj commented 1 year ago

What steps will reproduce the problem?

I am using resumable.js to upload the file. The resumable.js is in one website, and the backend chunk-upload is in another (it all works well if both are on the same site).

What is the expected result?

When both frontend and backend are in the same site, it all works. The chunks are created and the $fileReceived->isFinished() is triggered as expected.

What do you get instead?

When the file is sent from a different site (which is the setup I need), the chunks are created but the $fileReceived->isFinished() never gets called.

Additional info

When logging the $fileReceived->handler()->getPercentageDone(), I noticed something interesting: This is the log when all works well (both frontend and backend are in the same site)

[2023-09-13 22:35:01] local.DEBUG: Percentage done: 30  
[2023-09-13 22:35:01] local.DEBUG: Percentage done: 30  
[2023-09-13 22:35:01] local.DEBUG: Percentage done: 30  
[2023-09-13 22:35:01] local.DEBUG: Percentage done: 60  
[2023-09-13 22:35:01] local.DEBUG: Percentage done: 60  
[2023-09-13 22:35:01] local.DEBUG: Percentage done: 60  
[2023-09-13 22:35:01] local.DEBUG: Percentage done: 80  
[2023-09-13 22:35:01] local.DEBUG: Percentage done: 80  
[2023-09-13 22:35:01] local.DEBUG: Percentage done: 90  
[2023-09-13 22:35:01] local.DEBUG: Percentage done: 100  

And here is the log when it doesn't (frontend and backend are in different sites)

[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
[2023-09-13 22:23:55] local.DEBUG: Percentage done: 10  
It seems to get stuck at 10% but stops after the same amount of iterations. The chunks are created as expected. Q A
This Package Version 1.5
resumable.js 1.0.3
Laravel Framework Version 9.19
PHP version 8.0
Operating system Darwin iMac.local 22.6.0
tato-rj commented 1 year ago

I just switched these from true to false and it now works. Session is now false and Browser is now true. Can anybody explain why? Can I keep it this way?

'use' => [
    'session' => false, // should the chunk name use the session id? The uploader must send cookie!,
    'browser' => true, // instead of session we can use the ip and browser?
],
nerg4l commented 1 year ago

In case of session the session id is used as part of the identifier.

https://github.com/pionl/laravel-chunk-upload/blob/0564c77e451650408bd59090f3686e9bab781fb9/src/Handler/AbstractHandler.php#L107-L109

When browser is used, then the md5 hash of the user IP and user agent is used.

https://github.com/pionl/laravel-chunk-upload/blob/0564c77e451650408bd59090f3686e9bab781fb9/src/Handler/AbstractHandler.php#L112-L114

The session ID is probably changes every time because the browser blocks the set cookie or just simply does not sends it because the request is cross-domain.

It is better to use the session identifier because the IP and the user agent might be empty and can be the same between users.

tato-rj commented 1 year ago

Got it, thanks for the reply. Is there a specific cookie I should be sending from the sender app to the receiver?

BilalTariq01 commented 1 year ago

@tato-rj same issue but setting browser true and session false in config not working for me