From 67821ca485fcf231aee7b20fec09a17709f8c89f Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Wed, 28 Feb 2024 13:48:52 +0100 Subject: [PATCH] sort chunk before merging --- UPGRADE.md | 5 ++++- src/Stream/FileStream.php | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 8023860a..9cb41601 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,8 +1,11 @@ # Upgrade Notes +## 5.0.5 +- Sort chunked uploaded files before merging + ## 5.0.4 - Add Additional HrefTransformer validation for `$type` and `$id` [@patkul0](https://github.com/dachcom-digital/pimcore-formbuilder/pull/434) -- Fix chunked upload `$type` and `$id` [@life-style-de](https://github.com/dachcom-digital/pimcore-formbuilder/pull/430) +- Fix chunked upload merge [@life-style-de](https://github.com/dachcom-digital/pimcore-formbuilder/pull/430) ## 5.0.3 - Fix element type check in api channel [#423](https://github.com/dachcom-digital/pimcore-formbuilder/issues/423) diff --git a/src/Stream/FileStream.php b/src/Stream/FileStream.php index 1cd81bc8..4d68791b 100644 --- a/src/Stream/FileStream.php +++ b/src/Stream/FileStream.php @@ -4,6 +4,7 @@ use League\Flysystem\FilesystemException; use League\Flysystem\FilesystemOperator; +use League\Flysystem\StorageAttributes; use Pimcore\File; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\Request; @@ -184,7 +185,15 @@ public function combineChunks(array $options = []): array $fileSafeName = $this->getSafeFileName($options['fileName']); $tmpStream = tmpfile(); - $chunkFiles = $this->formBuilderChunkStorage->listContents($uuid); + $chunkFiles = $this->formBuilderChunkStorage->listContents($uuid)->toArray(); + + usort($chunkFiles, static function (StorageAttributes $a, StorageAttributes $b) { + + $pathInfoA = pathinfo($a->path()); + $pathInfoB = pathinfo($b->path()); + + return $pathInfoA['filename'] <=> $pathInfoB['filename']; + }); foreach ($chunkFiles as $chunkFile) { $chunkPathResource = $this->formBuilderChunkStorage->readStream($chunkFile->path());