PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / S3 / MultipartUploadingTrait.php
transferito / vendor / aws / aws-sdk-php / src / S3 Last commit date
Crypto 11 months ago Exception 11 months ago RegionalEndpoint 11 months ago UseArnRegion 11 months ago AmbiguousSuccessParser.php 11 months ago ApplyChecksumMiddleware.php 11 months ago BatchDelete.php 11 months ago BucketEndpointArnMiddleware.php 11 months ago BucketEndpointMiddleware.php 11 months ago CalculatesChecksumTrait.php 11 months ago EndpointRegionHelperTrait.php 11 months ago GetBucketLocationParser.php 11 months ago MultipartCopy.php 11 months ago MultipartUploader.php 11 months ago MultipartUploadingTrait.php 11 months ago ObjectCopier.php 11 months ago ObjectUploader.php 11 months ago PermanentRedirectMiddleware.php 11 months ago PostObject.php 11 months ago PostObjectV4.php 11 months ago PutObjectUrlMiddleware.php 11 months ago RetryableMalformedResponseParser.php 11 months ago S3Client.php 11 months ago S3ClientInterface.php 11 months ago S3ClientTrait.php 11 months ago S3EndpointMiddleware.php 11 months ago S3MultiRegionClient.php 11 months ago S3UriParser.php 11 months ago SSECMiddleware.php 11 months ago StreamWrapper.php 11 months ago Transfer.php 11 months ago ValidateResponseChecksumParser.php 11 months ago
MultipartUploadingTrait.php
137 lines
1 <?php
2 namespace Aws\S3;
3
4 use Aws\CommandInterface;
5 use Aws\Multipart\UploadState;
6 use Aws\ResultInterface;
7
8 trait MultipartUploadingTrait
9 {
10 /**
11 * Creates an UploadState object for a multipart upload by querying the
12 * service for the specified upload's information.
13 *
14 * @param S3ClientInterface $client S3Client used for the upload.
15 * @param string $bucket Bucket for the multipart upload.
16 * @param string $key Object key for the multipart upload.
17 * @param string $uploadId Upload ID for the multipart upload.
18 *
19 * @return UploadState
20 */
21 public static function getStateFromService(
22 S3ClientInterface $client,
23 $bucket,
24 $key,
25 $uploadId
26 ) {
27 $state = new UploadState([
28 'Bucket' => $bucket,
29 'Key' => $key,
30 'UploadId' => $uploadId,
31 ]);
32
33 foreach ($client->getPaginator('ListParts', $state->getId()) as $result) {
34 // Get the part size from the first part in the first result.
35 if (!$state->getPartSize()) {
36 $state->setPartSize($result->search('Parts[0].Size'));
37 }
38 // Mark all the parts returned by ListParts as uploaded.
39 foreach ($result['Parts'] as $part) {
40 $state->markPartAsUploaded($part['PartNumber'], [
41 'PartNumber' => $part['PartNumber'],
42 'ETag' => $part['ETag']
43 ]);
44 }
45 }
46
47 $state->setStatus(UploadState::INITIATED);
48
49 return $state;
50 }
51
52 protected function handleResult(CommandInterface $command, ResultInterface $result)
53 {
54 $partData = [];
55 $partData['PartNumber'] = $command['PartNumber'];
56 $partData['ETag'] = $this->extractETag($result);
57 if (isset($command['ChecksumAlgorithm'])) {
58 $checksumMemberName = 'Checksum' . strtoupper($command['ChecksumAlgorithm']);
59 $partData[$checksumMemberName] = $result[$checksumMemberName];
60 }
61 $this->getState()->markPartAsUploaded($command['PartNumber'], $partData);
62 }
63
64 abstract protected function extractETag(ResultInterface $result);
65
66 protected function getCompleteParams()
67 {
68 $config = $this->getConfig();
69 $params = isset($config['params']) ? $config['params'] : [];
70
71 $params['MultipartUpload'] = [
72 'Parts' => $this->getState()->getUploadedParts()
73 ];
74
75 return $params;
76 }
77
78 protected function determinePartSize()
79 {
80 // Make sure the part size is set.
81 $partSize = $this->getConfig()['part_size'] ?: MultipartUploader::PART_MIN_SIZE;
82
83 // Adjust the part size to be larger for known, x-large uploads.
84 if ($sourceSize = $this->getSourceSize()) {
85 $partSize = (int) max(
86 $partSize,
87 ceil($sourceSize / MultipartUploader::PART_MAX_NUM)
88 );
89 }
90
91 // Ensure that the part size follows the rules: 5 MB <= size <= 5 GB.
92 if ($partSize < MultipartUploader::PART_MIN_SIZE || $partSize > MultipartUploader::PART_MAX_SIZE) {
93 throw new \InvalidArgumentException('The part size must be no less '
94 . 'than 5 MB and no greater than 5 GB.');
95 }
96
97 return $partSize;
98 }
99
100 protected function getInitiateParams()
101 {
102 $config = $this->getConfig();
103 $params = isset($config['params']) ? $config['params'] : [];
104
105 if (isset($config['acl'])) {
106 $params['ACL'] = $config['acl'];
107 }
108
109 // Set the ContentType if not already present
110 if (empty($params['ContentType']) && $type = $this->getSourceMimeType()) {
111 $params['ContentType'] = $type;
112 }
113
114 return $params;
115 }
116
117 /**
118 * @return UploadState
119 */
120 abstract protected function getState();
121
122 /**
123 * @return array
124 */
125 abstract protected function getConfig();
126
127 /**
128 * @return int
129 */
130 abstract protected function getSourceSize();
131
132 /**
133 * @return string|null
134 */
135 abstract protected function getSourceMimeType();
136 }
137