Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/S3/MultipartUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class MultipartUploader extends AbstractUploader
* of the multipart upload and that is used to resume a previous upload.
* When this option is provided, the `bucket`, `key`, and `part_size`
* options are ignored.
* - add_content_md5: (boolean) Set to true to automatically calculate the
* MD5 checksum for the upload.
* - checksum_algorithm: (string, default=string(CRC32)) S3 Checksum
* Algorithm to use for upload.
*
* @param S3ClientInterface $client Client used for the upload.
* @param mixed $source Source of the data to upload.
Expand All @@ -70,6 +74,14 @@ public function __construct(
'key' => null,
'exception_class' => S3MultipartUploadException::class,
]);

if (isset($config['checksum_algorithm'])) {
$this->checksumAlgorithm = strtoupper($config['checksum_algorithm']);
$this->checksumParam = 'Checksum'.$this->checksumAlgorithm;
} else {
$this->checksumAlgorithm = 'CRC32';
$this->checksumParam = 'ChecksumCRC32';
}
}

protected function loadUploadWorkflowInfo()
Expand Down Expand Up @@ -133,6 +145,12 @@ protected function createPart($seekable, $number)
$data['AddContentMD5'] = true;
}

$data['ChecksumAlgorithm'] = $this->checksumAlgorithm;
$data[$this->checksumParam] = CalculatesChecksumTrait::getEncodedValue(
$this->checksumAlgorithm,
$body
);

$data['ContentLength'] = $contentLength;

return $data;
Expand Down
7 changes: 7 additions & 0 deletions src/S3/MultipartUploadingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected function handleResult(CommandInterface $command, ResultInterface $resu
$this->getState()->markPartAsUploaded($command['PartNumber'], [
'PartNumber' => $command['PartNumber'],
'ETag' => $this->extractETag($result),
$this->checksumParam => $result[$this->checksumParam]
]);
}

Expand All @@ -67,6 +68,10 @@ protected function getCompleteParams()
$params['MultipartUpload'] = [
'Parts' => $this->getState()->getUploadedParts()
];
$params['MultipartUpload'][$this->checksumParam] =
CalculatesChecksumTrait::getEncodedValue(
$this->checksumAlgorithm, $this->source
);

return $params;
}
Expand Down Expand Up @@ -107,6 +112,8 @@ protected function getInitiateParams()
$params['ContentType'] = $type;
}

$params['ChecksumAlgorithm'] = $this->checksumAlgorithm;

return $params;
}

Expand Down