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(); } 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');