/** * {@inheritdoc} */ protected function build() { $this->request = $this->client->getS3Request(RequestInterface::PUT, $this->get('bucket'), $this->get('key')); $this->applyDefaults($this->request); // Set the PUT copy specific headers $this->request->setHeader('x-amz-copy-source', QueryString::rawurlencode($this->get('copy_source'), array('/'))); if ($this->get('metadata_directive')) { $this->request->setHeader('x-amz-metadata-directive', strtoupper($this->get('metadata_directive'))); } if ($this->get('copy_source_if_match')) { $this->getRequestHeaders()->set('x-amz-copy-source-if-match', $this->get('copy_source_if_match')); } if ($this->get('copy_source_if_none_match')) { $this->request->setHeader('x-amz-copy-source-if-none-match', $this->get('copy_source_if_none_match')); } if ($this->get('copy_source_if_unmodified_since')) { $this->request->setHeader('x-amz-copy-source-if-unmodified-since', $this->get('copy_source_if_unmodified_since')); } if ($this->get('copy_source_if_modified_since')) { $this->request->setHeader('x-amz-copy-source-if-modified-since', $this->get('copy_source_if_modified_since')); } $this->request->getCurlOptions()->set(CURLOPT_LOW_SPEED_TIME, null); }
/** * Get a signed URL that is valid for a specific amount of time for a virtual * hosted bucket. * * @param string $bucket The bucket of the object. * @param string $key The key of the object. * @param int $duration The number of seconds the URL is valid. * @param bool $cnamed Whether or not the bucket should be referenced by a * CNAMEd URL. * @param bool $torrent Set to true to append ?torrent and retrieve the * torrent of the file. * * @return string Returns a signed URL. * * @throws LogicException when $torrent and $requesterPays is passed. * * @link http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTAuthentication.html */ public function getSignedUrl($bucket, $key, $duration, $cnamed = false, $torrent = false, $requesterPays = false) { if ($torrent && $requesterPays) { throw new \InvalidArgumentException('Cannot use ?requesterPays with ?torrent.'); } $expires = time() + ($duration ? $duration : 60); $plugin = $this->getEventManager()->getAttached('Guzzle\\Aws\\S3\\SignS3RequestPlugin'); $plugin = isset($plugin[0]) ? $plugin[0] : false; $isSigned = $plugin != false; $xAmzHeaders = $torrentStr = ''; $url = 'http://' . $bucket . ($cnamed ? '' : '.' . $this->getConfig()->get('region')); if ($key) { $url .= '/' . $key; } $qs = new QueryString(); if ($isSigned) { $qs->add('AWSAccessKeyId', $this->getAccessKeyId())->add('Expires', $expires); } if ($torrent) { $qs->add('torrent', false); $torrentStr = '?torrent'; } else { if ($requesterPays) { $qs->add('x-amz-request-payer', 'requester'); $xAmzHeaders .= 'x-amz-request-payer:requester' . "\n"; } } if ($isSigned) { $strToSign = sprintf("GET\n\n\n{$expires}\n{$xAmzHeaders}/%s/%s{$torrentStr}", QueryString::rawurlencode($bucket, array('/')), QueryString::rawurlencode($key, array('/'))); $qs->add('Signature', $plugin->getSignature()->signString($strToSign)); } return $url . $qs; }