private function getInfo() { if ($this->info === null) { $result = $this->client->headObject(array('Bucket' => $this->get('bucket'), 'Key' => $this->get('path'))); $this->info = array(); $this->info["size"] = (int) $result->get("ContentLength"); $this->info["hash"] = substr($result->get("ETag"), 1, 32); $this->info["type"] = $result->get("ContentType"); } return $this->info; }
public function getSize($path) { $options = $this->_getOptions($path); try { return (int) $this->_client->headObject($options)->get('ContentLength'); } catch (\Exception $e) { throw new CM_Exception('Cannot get size for path', null, ['path' => $path, 'originalExceptionMessage' => $e->getMessage()]); } }
public function getSize($path) { $options = $this->_getOptions($path); try { return (int) $this->_client->headObject($options)->get('ContentLength'); } catch (\Exception $e) { throw new CM_Exception('Cannot get size for `' . $path . '`: ' . $e->getMessage()); } }
private function getFilesToDownloadFromManifest($path) { $s3Client = new \Aws\S3\S3Client(['credentials' => ['key' => $this->s3key, 'secret' => $this->s3secret], 'region' => $this->s3region, 'version' => '2006-03-01']); $path = parse_url($path); try { $response = $s3Client->getObject(['Bucket' => $path['host'], 'Key' => ltrim($path['path'], '/')]); } catch (AwsException $e) { throw new Exception('Unable to download file from S3: ' . $e->getMessage()); } $manifest = json_decode((string) $response['Body'], true); return array_map(function ($entry) use($s3Client) { $path = parse_url($entry['url']); try { // file validation $s3Client->headObject(['Bucket' => $path['host'], 'Key' => ltrim($path['path'], '/')]); } catch (S3Exception $e) { throw new Exception(sprintf('File "%s" download error: %s', $entry['url'], $e->getMessage()), Exception::MANDATORY_FILE_NOT_FOUND); } return $entry['url']; }, $manifest['entries']); }