From 59f48d2527c4a949095dd1c6b35ed9e58ac0f7c3 Mon Sep 17 00:00:00 2001 From: Yurguis Garcia Date: Fri, 9 May 2025 10:52:21 -0400 Subject: [PATCH 1/2] feat: Added part_size param to transfer manager for MultipartUploader. --- src/S3/Transfer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/S3/Transfer.php b/src/S3/Transfer.php index 7679950b4e..01a0205c35 100644 --- a/src/S3/Transfer.php +++ b/src/S3/Transfer.php @@ -25,6 +25,7 @@ class Transfer implements PromisorInterface private $sourceMetadata; private $destination; private $concurrency; + private $partSize; private $mupThreshold; private $before; private $after; @@ -118,6 +119,9 @@ public function __construct( $this->concurrency = isset($options['concurrency']) ? $options['concurrency'] : MultipartUploader::DEFAULT_CONCURRENCY; + $this->partSize = isset($options['part_size']) + ? $options['part_size'] + : MultipartUploader::PART_MIN_SIZE; $this->mupThreshold = isset($options['mup_threshold']) ? $options['mup_threshold'] : 16777216; @@ -387,6 +391,7 @@ private function uploadMultipart($filename) 'before_upload' => $this->before, 'before_complete' => $this->before, 'concurrency' => $this->concurrency, + 'part_size' => $this->partSize, 'add_content_md5' => $this->addContentMD5 ]))->promise(); } From 89fdc74688ca45a08d59ba704d2f111e6b355748 Mon Sep 17 00:00:00 2001 From: Yurguis Garcia Date: Thu, 22 May 2025 12:18:18 -0400 Subject: [PATCH 2/2] feat: Added unit test for part_size. --- tests/S3/TransferTest.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/S3/TransferTest.php b/tests/S3/TransferTest.php index 7007e67a15..9e07f90b86 100644 --- a/tests/S3/TransferTest.php +++ b/tests/S3/TransferTest.php @@ -253,6 +253,40 @@ public function testDoesMultipartForLargeFilesWithFileInfoAsSource() `rm -rf $dir`; } + public function testMultipartForLargeFilesDoesUsePartSize() + { + $s3 = $this->getTestClient('s3'); + $this->addMockResults($s3, [ + new Result(['UploadId' => '123']), + new Result(['ETag' => 'a']), + new Result(['ETag' => 'b']), + new Result(['UploadId' => '123']), + ]); + + $dir = sys_get_temp_dir() . '/unittest'; + `rm -rf $dir`; + mkdir($dir); + $filename = new SplFileInfo($dir . '/large.txt'); + $f = fopen($filename, 'w+'); + $line = str_repeat('.', 1024); + for ($i = 0; $i < 20000; $i++) { + fwrite($f, $line); + } + fclose($f); + + $res = fopen('php://temp', 'r+'); + $t = new Transfer($s3, $dir, 's3://foo/bar', [ + 'part_size' => 1024 * 1024 * 10, + 'debug' => $res + ]); + + $t->transfer(); + rewind($res); + $output = stream_get_contents($res); + $this->assertStringNotContainsString("Transferring $filename -> s3://foo/bar/large.txt (UploadPart) : Part=3", $output); + `rm -rf $dir`; + } + public function testDownloadsObjects() { $s3 = $this->getTestClient('s3');