-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
Files are appended together when uploading two different files with same filename or same file with same filename uploaded from two browsers #52
Comments
Uploads are differentiated using unique
Again, I suspect there is some cache issue in your setup. If you upload same file again with same |
I used File cache and works fine and problem not solved! Again, I explain problem: I Upload a.mp4 (100mb) file from chrome browser and it's successfully uploaded in /storage path. Again, I upload a.mp4 (100mb) file from firefox browser and it's successfully uploaded in /storage path. But /storage/a.mp4 size is 200mb now! |
@airani can you provide cache contents for those cases. i.e first, upload a file and copy its cache key and contents. Then, upload same file again from another browser and copy cache key and contents. |
Closing because of no response |
@ankitpokhrel this issue should not be closed. |
@Yangwendaxia @airani Looks like you guys are trying to upload same file from different browsers in parallel. In that case, of course, one request is going to override another as the package is not designed for the distributed upload. But I agree that it would be great if we could make it work for distributed uploads. |
@ankitpokhrel I'm using Uppy as the frontend widget with TUS PHP in the back. No matter what the set of circumstances (same browser, different, etc); if you upload the same filename to same directory, it appends it on to the existing file. To reproduce: |
@drastik When you clear browser local storage, uppy will send new request for the upload. Here, the file is being appended because file with same name already exist in the server. If you want to prevent that, you can organize your uploads in the server. For instance, you can prefix your file name using upload key or save all new uploads in a separate folder. You can change <?php
require __DIR__ . '/../vendor/autoload.php';
$server = new \TusPhp\Tus\Server('redis');
if (strtolower($server->getRequest()->method()) === 'post') {
$baseDir = __DIR__ . '/../uploads/';
$uploadPath = $baseDir . $server->getUploadKey();
if ( ! is_dir($uploadPath)) {
mkdir($uploadPath);
}
$server->setUploadDir($uploadPath);
}
$response = $server->serve();
$response->send();
exit(0); // Exit from current PHP process. |
Right. |
Oops, early comment. @ankitpokhrel Do you see an issue with this approach? I understand your suggestion as well, and I may do that.. though I had wanted to avoid renaming user's files or destination folders, since my other framework was handling all of that. |
Wow! You guys are having an interesting discussion going on. When I have sometime I will try to reproduce the error at my end and will try to figure out. Regarding the actual query, I think there's no way for server to know which file belong to which client other than doing the manual tagging on the file itself. So, like already provided here, the easiest solution would be to identify the client at application level and handle the uploads accordingly. Otherwise, have to send extra metadata with file itself to identify the individual client and respective uploaded contents which I think is extra work for Tus-PHP client and server end. |
Reopening this issue because of ongoing discussions |
Can we match the file from client to cache by |
@drastik Won't you have same issue again after you clear your server cache (same as you cleared localStorage)?
We can do it only if all clients sends checksum on their request. But it is not the case even in uppy. That is why we have this condition to ignore checksum if we don't get any checksum in request header. Lines 617 to 623 in 9a34d98
|
I like your suggestion for folders based on UUID @ankitpokhrel . I think we can close this issue. Thank you very much for this project by the way. I have a patch I will commit for properly finding filename from Upload-metadata in the case where your client sends extra values, I will create a separate issue for the PR. |
Hi everybody ! The context : we have a folder "TEST" with inside a file a1.jpg and a "SUBTEST" subfolder with inside a different file but with the same name, "a1.jpg" Now in Server class, in the handlePost method we can change the filename so that on the server it's now unique (based on uuid). This way, there is no concatenation as discussed aboved. Shusss, |
I've been dealing with the same problem. What I've come up with, which seems to be working great with testing (resumes with no problem and no filename collisions) is to extend the Server class and copy the handlePost() method into my new class, then simply prepend a uniqid() to the fileName in the path:
This got me thinking that maybe a better, permanent solution would be to offer the possibility of a $filePath callback. I tried this out in my extended class and it's working the same as above:
Now in the handlePost():
Which finally gives you the ability to simply:
|
What about if we implement same approach as OS deals with same file names? if user is trying to upload again |
If upload two diffrent files with same filename or same file with same filename upload from two browsers files append together
The text was updated successfully, but these errors were encountered: