示例#1
0
 /**
  * Get an authorization url with expire time
  *
  * @param string $bucket_name The bucket name.
  * @param string $object_name The object path.
  * @param number $timestamp
  * @param number $expiration_in_seconds The valid time in seconds.
  * @param mixed $options The extra http request headers or params.
  *
  * @return string
  */
 public function generatePresignedUrl($bucket_name, $key, $timestamp = 0, $expiration_in_seconds = 1800, $headers = array(), $params = array(), $headers_to_sign = array(), $config = array())
 {
     $config = array_merge(array(), $this->config, $config);
     $path = $this->getPath($config, $bucket_name, $key);
     $headers[HttpHeaders::HOST] = preg_replace('/(\\w+:\\/\\/)?([^\\/]+)\\/?/', '$2', $config['endpoint']);
     $authorization = $this->auth->generateAuthorization(HttpMethod::GET, $path, $params, $headers, $timestamp, $expiration_in_seconds, $headers_to_sign);
     return sprintf("%s%s?authorization=%s", $config['endpoint'], $path, Coder::urlEncode($authorization));
 }
示例#2
0
 /**
  * @param string $path The bucket and object path.
  * @param array @param The query strings
  *
  * @return string The complete request url path with query string.
  */
 private function getRequestUrl($path, $params)
 {
     $uri = Coder::urlEncodeExceptSlash($path);
     $query_string = implode("&", array_map(function ($k, $v) {
         return $k . "=" . Coder::urlEncode($v);
     }, array_keys($params), $params));
     if (!is_null($query_string) && $query_string != "") {
         $uri = $uri . "?" . $query_string;
     }
     $parsed_url = parse_url($this->config['endpoint']);
     $port = '';
     $protocol = isset($parsed_url['scheme']) ? $parsed_url['scheme'] : 'http';
     if ($protocol !== 'http' && $protocol !== 'https') {
         throw new \InvalidArgumentException(sprintf("Invalid protocol: %s, either HTTP or HTTPS is expected.", $protocol));
     }
     return sprintf("%s%s", $this->config['endpoint'], $uri);
 }