<?php

defined('BASEPATH') OR exit('No direct script access allowed');

require APPPATH .'vendor/aws-sdk/aws-autoloader.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;


class aws_s3
{
	private $S3Client;
	function __construct()
    {
        // Construct the parent class
       // parent::__construct();
    
	    	$s3_credentials = array(  'credentials' => array('key' => SCHOOL_AWS_KEY,'secret' => SCHOOL_AWS_SECRET), 'version' => 'latest','region'  => 'ap-south-1' );
	    	$this->S3Client = S3Client::factory($s3_credentials);
				
			

    }

    public function get_s3_url($key)
    {
    	try
    	{
    		$cmd = $this->S3Client->getCommand('GetObject', ['Bucket' => SCHOOL_BUCKET_NAME,'Key'=> $key ]);
			$request = $this->S3Client->createPresignedRequest($cmd, '+5 minutes');
			$presignedUrl = (string) $request->getUri();
			return $presignedUrl;
      
    	}
    	catch(AwsException $e)
    	{
    		log_message('ERROR',$e->getMessage());	
			return $e->getMessage();
    	}
    }
}

	

