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

Chunk are appended in the wrong order when the upload creates 10 chunks or more #38

Closed
kerwan opened this issue May 23, 2018 · 2 comments

Comments

@kerwan
Copy link

kerwan commented May 23, 2018

If you make an upload that leads to more than 10 chunks, they are appended in the wrong order.
I think this has to do with the sort function which does not take the part numbers into account correctly.
So file xxxxxxxx-10.part is appended before xxxxxxxx-2.part because of the sorting.

I have already applied the fix proposed in another thread by setting browser = true and session = false
for the filenames. So I assured my part filenames are consistent throught the whole upload.

I am using dropzone.js to handle the upload client side, and I checked that the chunk indexes, order and total are all correct.

Sorting the files with natural case seems to fix the problem.
In function buildFullFileFromChunks() from ParallelSave.php

$chunkFiles = $this->savedChunksFiles()->sort();

I replace with this

// Sorting file collection with natural case so xxxx-10.part does not get before xxxx-2.part
$chunkFiles = $this->savedChunksFiles();
$items = $chunkFiles->all();
natcasesort($items);
$chunkFiles = collect($items);

And it solves the problem.

If this a mistake from me that can be resolved without updating the plugin, I'll be happy to be directed to the solution.

Apart from this, it is an excellent plugin :-).

@kerwan kerwan changed the title Chunk are appended in the wrong order Chunk are appended in the wrong order when the upload creates 10 chunks or more May 23, 2018
@pionl
Copy link
Owner

pionl commented May 24, 2018

Sorry for the problem, my bad. You are correct. I thought that Collection->sort will handle this. I've tested the sorting without special chars and it sorted correctly. Didn't have to much to test it properly - currently not using project that needs this 😣

I've implemented the change and its OK now 👍

New version is on the way.

@pionl pionl closed this as completed in c10f43d May 24, 2018
@kerwan
Copy link
Author

kerwan commented May 24, 2018

Great ! Thanks for your fast answer.

I'm using this for a project that will use various file sizes (from very small to a few GB) so I'll be happy to give feedback about this whenever I can.

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

2 participants