Amazon_S3_And_CloudFront::get_s3client PHP Method

get_s3client() public method

Get the S3 client
public get_s3client ( boolean | string $region = false, boolean $force = false ) : Aws\S3\S3Client
$region boolean | string specify region to client for signature
$force boolean force return of new S3 client when swapping regions
return Aws\S3\S3Client
    function get_s3client($region = false, $force = false)
    {
        if (is_null($this->s3client) || $force) {
            if ($region) {
                $args = array('region' => $this->translate_region($region), 'signature' => 'v4');
            } else {
                $args = array();
            }
            $client = $this->aws->get_client()->get('s3', $args);
            $this->set_client($client);
        }
        return $this->s3client;
    }

Usage Example

 /**
  * Download a file from S3 if the file does not exist locally and places it where
  * the attachment's file should be.
  *
  * @param array  $s3_object
  * @param string $file
  *
  * @return string|bool File if downloaded, false on failure
  */
 protected function copy_s3_file_to_server($s3_object, $file)
 {
     try {
         $this->as3cf->get_s3client($s3_object['region'], true)->getObject(array('Bucket' => $s3_object['bucket'], 'Key' => $s3_object['key'], 'SaveAs' => $file));
     } catch (Exception $e) {
         error_log(sprintf(__('There was an error attempting to download the file %s from S3: %s', 'as3cf'), $s3_object['key'], $e->getMessage()));
         return false;
     }
     return $file;
 }
All Usage Examples Of Amazon_S3_And_CloudFront::get_s3client
Amazon_S3_And_CloudFront