コード例 #1
0
ファイル: AwsS3.php プロジェクト: cargomedia/cm
 public function read($path)
 {
     $options = $this->_getOptions($path);
     try {
         return (string) $this->_client->getObject($options)->get('Body');
     } catch (\Exception $e) {
         throw new CM_Exception('Cannot read contents of path.', null, ['path' => $path, 'originalExceptionMessage' => $e->getMessage()]);
     }
 }
コード例 #2
0
ファイル: AwsS3.php プロジェクト: NicolasSchmutz/cm
 public function read($path)
 {
     $options = $this->_getOptions($path);
     try {
         return (string) $this->_client->getObject($options)->get('Body');
     } catch (\Exception $e) {
         throw new CM_Exception('Cannot read contents of `' . $path . '`: ' . $e->getMessage());
     }
 }
コード例 #3
0
ファイル: s3file.php プロジェクト: JoonasMelin/BotQueue
 public function download($srcPath, $dstPath)
 {
     //make directory.
     $dir = dirname($dstPath);
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     if (!is_writable($dir)) {
         return false;
     }
     $this->client->getObject(array('Bucket' => $this->get('bucket'), 'Key' => $this->get('path'), 'SaveAs' => $dstPath));
     $this->save();
     // todo Verify that it actually did work
     return true;
 }
コード例 #4
0
 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']);
 }
コード例 #5
0
<?php

/**
 * Loads test fixtures into S3
 */
date_default_timezone_set('Europe/Prague');
ini_set('display_errors', true);
error_reporting(E_ALL);
$basedir = dirname(__DIR__);
require_once $basedir . '/vendor/autoload.php';
$client = new \Aws\S3\S3Client(['region' => 'us-east-1', 'version' => '2006-03-01', 'credentials' => ['key' => getenv('AWS_ACCESS_KEY'), 'secret' => getenv('AWS_SECRET_KEY')]]);
$client->getObject(['Bucket' => 'keboola-configs', 'Key' => 'drivers/snowflake/snowflake_linux_x8664_odbc.2.12.87.tgz', 'SaveAs' => './snowflake_linux_x8664_odbc.tgz']);
コード例 #6
0
 private function downloadManifest($path)
 {
     $s3Client = new \Aws\S3\S3Client(['credentials' => ['key' => $this->s3key, 'secret' => $this->s3secret], 'region' => $this->s3region, 'version' => '2006-03-01']);
     $path = parse_url($path);
     $response = $s3Client->getObject(['Bucket' => $path['host'], 'Key' => ltrim($path['path'], '/')]);
     return json_decode((string) $response['Body'], true);
 }