Example #1
0
 /**
  * Constructor.
  *
  * @since 160719 Initial release.
  *
  * @param Classes\App $App Instance of App.
  */
 public function __construct(Classes\App $App)
 {
     parent::__construct($App);
     $this->Sdk = new AwsLib\Sdk(['version' => 'latest', 'region' => $this->App->Config->©aws['©region'], 'credentials' => ['key' => $this->App->Config->©aws['©access_key'], 'secret' => $this->App->Config->©aws['©secret_key']]]);
     $this->S3Client = $this->Sdk->createS3(['version' => $this->App->Config->©aws['©s3_version']]);
     // A quick example of how this can be used in PHP.
     // $this->S3Client->registerStreamWrapper();
     // See: <http://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/s3-stream-wrapper.html>
 }
Example #2
0
 public function uploadObject($source, $bucket, $key, $acl = self::ACL_PRIVATE)
 {
     $this->source = $source;
     $this->bucket = $bucket;
     $this->key = $key;
     $this->acl = $acl;
     $this->scenario = 'put';
     if ($this->validate()) {
         $sdk = new Sdk(['version' => 'latest', 'region' => Yii::$app->params['amazon']['region'], 'credentials' => Yii::$app->params['amazon']['credentials']]);
         $s3 = $sdk->createS3();
         $file = null;
         try {
             $file = fopen($this->source, 'r');
             $result = $s3->upload($this->bucket, $this->key, $file, $this->acl, ['Content-Type' => $this->getContentType()]);
             return $result->get('ObjectURL');
         } catch (\Exception $e) {
             Yii::error('Error uploading files to S3. ' . $e->getMessage());
         }
         if ($file != null) {
             fclose($file);
         }
         return false;
     } else {
         return false;
     }
 }
Example #3
0
 protected function load()
 {
     if (!$this->s3Client) {
         $this->s3Client = DependencyRegistry::load("S3V2", function () {
             $sdk = new Sdk(["region" => "us-east-1", "version" => "latest"]);
             return $sdk->createS3();
         });
     }
 }