Skip to content

Commit

Permalink
refactor s3 chunked upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Nov 25, 2024
1 parent 39cf3e8 commit 93ce8a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function uploadData(string $data, string $path, string $contentType, int

$etag = $this->uploadPart($data, $path, $contentType, $chunk, $uploadId);
$metadata['parts'] ??= [];
$metadata['parts'][] = ['partNumber' => $chunk, 'etag' => $etag];
$metadata['parts'][$chunk] = $etag;
$metadata['chunksUploaded'] ??= [];
$metadata['chunks'] ??= 0;
// skip incrementing if the chunk was re-uploaded
Expand Down Expand Up @@ -435,8 +435,8 @@ protected function completeMultipartUpload(string $path, string $uploadId, array
$uri = $path !== '' ? '/'.\str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/';

$body = '<CompleteMultipartUpload>';
foreach ($parts as $part) {
$body .= "<Part><ETag>{$part['etag']}</ETag><PartNumber>{$part['partNumber']}</PartNumber></Part>";
foreach ($parts as $key => $etag) {
$body .= "<Part><ETag>{$etag}</ETag><PartNumber>{$key}</PartNumber></Part>";
}
$body .= '</CompleteMultipartUpload>';

Expand Down
9 changes: 3 additions & 6 deletions tests/Storage/S3Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ public function testPartUpload()
$cc = fopen($op, 'wb');
fwrite($cc, $contents);
fclose($cc);
$etag = $this->object->upload($op, $dest, $chunk, $chunks, $metadata);
$parts[] = ['partNumber' => $chunk, 'etag' => $etag];
$this->object->upload($op, $dest, $chunk, $chunks, $metadata);
$start += strlen($contents);
$chunk++;
fseek($handle, $start);
Expand Down Expand Up @@ -322,8 +321,7 @@ public function testPartUploadRetry()
$cc = fopen($op, 'wb');
fwrite($cc, $contents);
fclose($cc);
$etag = $this->object->upload($op, $dest, $chunk, $chunks, $metadata);
$parts[] = ['partNumber' => $chunk, 'etag' => $etag];
$this->object->upload($op, $dest, $chunk, $chunks, $metadata);
$start += strlen($contents);
$chunk++;
if ($chunk == 2) {
Expand All @@ -345,8 +343,7 @@ public function testPartUploadRetry()
$cc = fopen($op, 'wb');
fwrite($cc, $contents);
fclose($cc);
$etag = $this->object->upload($op, $dest, $chunk, $chunks, $metadata);
$parts[] = ['partNumber' => $chunk, 'etag' => $etag];
$this->object->upload($op, $dest, $chunk, $chunks, $metadata);
$start += strlen($contents);
$chunk++;
fseek($handle, $start);
Expand Down

0 comments on commit 93ce8a4

Please sign in to comment.