| @@ -48,8 +48,10 @@ | ||
| 48 | 48 | * When this option is provided, the `bucket`, `key`, and `part_size` |
| 49 | 49 | * options are ignored. |
| 50 | 50 | * - source_metadata: (Aws\ResultInterface) An object that represents the |
| 51 | 51 | * result of executing a HeadObject command on the copy source. |
| 52 | + * - display_progress: (boolean) Set true to track status in 1/8th increments | |
| 53 | + * for upload. | |
| 52 | 54 | * |
| 53 | 55 | * @param S3ClientInterface $client Client used for the upload. |
| 54 | 56 | * @param string|array $source Location of the data to be copied (in the |
| 55 | 57 | * form /<bucket>/<key>). If the key contains a '?' |
| @@ -64,8 +66,11 @@ | ||
| 64 | 66 | } else { |
| 65 | 67 | $this->source = $this->getInputSource($source); |
| 66 | 68 | } |
| 67 | 69 | parent::__construct($client, \array_change_key_case($config) + ['source_metadata' => null]); |
| 70 | + if ($this->displayProgress) { | |
| 71 | + $this->getState()->setProgressThresholds($this->sourceMetadata["ContentLength"]); | |
| 72 | + } | |
| 68 | 73 | } |
| 69 | 74 | /** |
| 70 | 75 | * An alias of the self::upload method. |
| 71 | 76 | * |
| @@ -103,13 +108,16 @@ | ||
| 103 | 108 | // The source parameter here is usually a string, but can be overloaded as an array |
| 104 | 109 | // if the key contains a '?' character to specify where the query parameters start |
| 105 | 110 | if (\is_array($this->source)) { |
| 106 | 111 | $key = \str_replace('%2F', '/', \rawurlencode($this->source['source_key'])); |
| 107 | - $data['CopySource'] = '/' . $this->source['source_bucket'] . '/' . $key; | |
| 112 | + $bucket = $this->source['source_bucket']; | |
| 108 | 113 | } else { |
| 109 | 114 | list($bucket, $key) = \explode('/', \ltrim($this->source, '/'), 2); |
| 110 | - $data['CopySource'] = '/' . $bucket . '/' . \implode('/', \array_map('urlencode', \explode('/', \rawurldecode($key)))); | |
| 115 | + $key = \implode('/', \array_map('urlencode', \explode('/', \rawurldecode($key)))); | |
| 111 | 116 | } |
| 117 | + $uri = ArnParser::isArn($bucket) ? '' : '/'; | |
| 118 | + $uri .= $bucket . '/' . $key; | |
| 119 | + $data['CopySource'] = $uri; | |
| 112 | 120 | $data['PartNumber'] = $partNumber; |
| 113 | 121 | if (!empty($this->sourceVersionId)) { |
| 114 | 122 | $data['CopySource'] .= "?versionId=" . $this->sourceVersionId; |
| 115 | 123 | } |
| @@ -175,13 +183,9 @@ | ||
| 175 | 183 | * @return string The source, starting with a slash if it's not an arn |
| 176 | 184 | */ |
| 177 | 185 | private function getInputSource($inputSource) |
| 178 | 186 | { |
| 179 | - if (ArnParser::isArn($inputSource)) { | |
| 180 | - $sourceBuilder = ''; | |
| 181 | - } else { | |
| 182 | - $sourceBuilder = "/"; | |
| 183 | - } | |
| 187 | + $sourceBuilder = ArnParser::isArn($inputSource) ? '' : '/'; | |
| 184 | 188 | $sourceBuilder .= \ltrim(\rawurldecode($inputSource), '/'); |
| 185 | 189 | return $sourceBuilder; |
| 186 | 190 | } |
| 187 | 191 | } |