Skip to content

Commit cf5b24b

Browse files
committed
Do not rename chunks if the upload process is not yet finished.
Otherwise you will end up having a completly broken order of reassembling. Addresses: #21
1 parent c442135 commit cf5b24b

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Controller/AbstractChunkedController.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,12 @@ protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $re
6060

6161
if ($chunkManager->getLoadDistribution()) {
6262
$chunks = $chunkManager->getChunks($uuid);
63-
$assembled = $chunkManager->assembleChunks($chunks);
63+
$assembled = $chunkManager->assembleChunks($chunks, true, $last);
6464
}
6565

6666
// if all chunks collected and stored, proceed
6767
// with reassembling the parts
6868
if ($last) {
69-
if (!$chunkManager->getLoadDistribution()) {
70-
$chunks = $chunkManager->getChunks($uuid);
71-
$assembled = $chunkManager->assembleChunks($chunks);
72-
}
73-
7469
$path = $assembled->getPath();
7570

7671
// create a temporary uploaded file to meet the interface restrictions

Uploader/Chunk/ChunkManager.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function addChunk($uuid, $index, UploadedFile $chunk, $original)
4848
return $chunk->move($path, $name);
4949
}
5050

51-
public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true)
51+
public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true, $renameChunk = false)
5252
{
5353
$iterator = $chunks->getIterator()->getInnerIterator();
5454

@@ -71,9 +71,15 @@ public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true)
7171
$iterator->next();
7272
}
7373

74+
$name = $base->getBasename();
75+
76+
if ($renameChunk) {
77+
$name = preg_replace('/^(\d+)_/', '', $base->getBasename());
78+
}
79+
7480
// remove the prefix added by self::addChunk
7581
$assembled = new File($base->getRealPath());
76-
$assembled = $assembled->move($base->getPath(), preg_replace('/^(.+?)_/', '', $base->getBasename()));
82+
$assembled = $assembled->move($base->getPath(), $name);
7783

7884
return $assembled;
7985
}

0 commit comments

Comments
 (0)