AWSREK
This commit is contained in:
parent
35c5c39eb5
commit
39b10d9faa
1168
api/application/composer.lock
generated
1168
api/application/composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -351,4 +351,6 @@ $route['regenerateSaleReport'] = 'Sales_PD_Controller/regenerateSaleReport';
|
|||||||
$route['resendSaleReportMail'] = 'Sales_PD_Controller/resendSaleReportMail';
|
$route['resendSaleReportMail'] = 'Sales_PD_Controller/resendSaleReportMail';
|
||||||
|
|
||||||
$route['generateOTP'] = 'User_Management_Controller/generateOTP';
|
$route['generateOTP'] = 'User_Management_Controller/generateOTP';
|
||||||
$route['verifyOTP'] = 'User_Management_Controller/verifyOTP';
|
$route['verifyOTP'] = 'User_Management_Controller/verifyOTP';
|
||||||
|
|
||||||
|
$route['awsrek/(:any)'] = 'Test/testAwsrek';
|
||||||
@ -2128,7 +2128,7 @@ public function assignPDTempalate($data)
|
|||||||
$this->checkEmptyQueryParams($_GET);
|
$this->checkEmptyQueryParams($_GET);
|
||||||
$page = 0;$limit = 1000;$sort = 'DESC';$pdofficerid = "";$datetype = "";$fdate ="";$tdate ="";
|
$page = 0;$limit = 1000;$sort = 'DESC';$pdofficerid = "";$datetype = "";$fdate ="";$tdate ="";
|
||||||
$lenderid = "";$status="";$lender_details = array();
|
$lenderid = "";$status="";$lender_details = array();
|
||||||
$pdagencyid = "";$vendor_pdofficer = "";$user_type = "";$createdby="";
|
$pdagencyid = "";$vendor_pdofficer = "";$user_type = "";$createdby="";$client="";
|
||||||
if($this->get('page')) { $page = $this->get('page'); }
|
if($this->get('page')) { $page = $this->get('page'); }
|
||||||
if($this->get('limit')){ $limit = $this->get('limit'); }
|
if($this->get('limit')){ $limit = $this->get('limit'); }
|
||||||
if($this->get('sort')) { $sort = $this->get('sort'); }
|
if($this->get('sort')) { $sort = $this->get('sort'); }
|
||||||
|
|||||||
@ -11,6 +11,7 @@ class Test extends REST_Controller {
|
|||||||
$this->load->helper(array('form', 'url'));
|
$this->load->helper(array('form', 'url'));
|
||||||
//$this->load->model('test_model');
|
//$this->load->model('test_model');
|
||||||
$this->load->library('asynclibrary');
|
$this->load->library('asynclibrary');
|
||||||
|
$this->load->library('aws_rekonition');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,4 +73,28 @@ class Test extends REST_Controller {
|
|||||||
// $this->test_model->insert($email, $name);
|
// $this->test_model->insert($email, $name);
|
||||||
//echo "insert";
|
//echo "insert";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function testAwsrek_get()
|
||||||
|
{
|
||||||
|
$fk_entity_id = $this->uri->segment(2);//die();
|
||||||
|
//echo $fk_entity_id;die();
|
||||||
|
// $data['student_details'] = array('name' => 'kumar','age' => '62','param' => $fk_entity_id);
|
||||||
|
|
||||||
|
// $this->response($data,REST_Controller::HTTP_OK);
|
||||||
|
//echo 'Hi';die();
|
||||||
|
// $data['dataStatus'] = true;
|
||||||
|
// $data['status'] = REST_Controller::HTTP_OK;
|
||||||
|
// $data['rec'] = $this->aws_rekonition->listAllBuckets();
|
||||||
|
$data= $this->aws_rekonition->listAllBuckets();
|
||||||
|
print_r($data);
|
||||||
|
|
||||||
|
// foreach($data as $k => $v)
|
||||||
|
// {
|
||||||
|
// echo $k .' - '. print_r($v);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $this->response($data,REST_Controller::HTTP_OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
329
api/application/libraries/AWS_REKONITION.php
Normal file
329
api/application/libraries/AWS_REKONITION.php
Normal file
@ -0,0 +1,329 @@
|
|||||||
|
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
include_once APPPATH.'/vendor/autoload.php';
|
||||||
|
use Aws\Rekognition\RekognitionClient;
|
||||||
|
//use Aws\AwsClient;
|
||||||
|
// use Aws\Exception\Rekognition;
|
||||||
|
use Aws\Exception\AwsException;
|
||||||
|
use Aws\CommandPool;
|
||||||
|
|
||||||
|
class AWS_REKONITION
|
||||||
|
{
|
||||||
|
private $RekognitionClient;
|
||||||
|
private $name = "TEST";
|
||||||
|
private $CI;
|
||||||
|
private $s3_properties;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// Construct the parent class
|
||||||
|
//parent::__construct();
|
||||||
|
|
||||||
|
$this->CI =& get_instance();
|
||||||
|
$this->s3_properties = array('region'=>'ap-south-1','version'=>'latest','credentials' => array(
|
||||||
|
'key' =>'AKIAR7TQUR2JRVZMMGLC',
|
||||||
|
'secret' => 'G0tLAEkHaaWfoTzm0y7f3RyxBsAN6JDJjElHufKW'
|
||||||
|
));
|
||||||
|
$this->RekognitionClient = RekognitionClient::factory($this->s3_properties);
|
||||||
|
//print_r($this->s3_properties);
|
||||||
|
// echo "Called";
|
||||||
|
// $this->setCors('lender8');
|
||||||
|
// die();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function yyy()
|
||||||
|
{
|
||||||
|
echo "listAllBuckets";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listAllBuckets()
|
||||||
|
{
|
||||||
|
// echo "listAllBuckets";
|
||||||
|
$result = array('aksj'=>'sana');
|
||||||
|
$sourceImg = 'will1.jpg';
|
||||||
|
$targetImg = 'will2.jpg';
|
||||||
|
|
||||||
|
try{
|
||||||
|
$result = $this->RekognitionClient->compareFaces([
|
||||||
|
// 'QualityFilter' => 'NONE|AUTO|LOW|MEDIUM|HIGH',
|
||||||
|
'QualityFilter' => 'NONE',
|
||||||
|
'SimilarityThreshold' => 1.0,
|
||||||
|
'SourceImage' => [ // REQUIRED
|
||||||
|
'Bytes' => file_get_contents('C:\Users\Venba\Pictures\cropped.png'),
|
||||||
|
// 'S3Object' => [
|
||||||
|
// 'Bucket' => 'awsrekonition',
|
||||||
|
// 'Name' => $sourceImg,
|
||||||
|
// 'Version' => 'any',],
|
||||||
|
//
|
||||||
|
],
|
||||||
|
'TargetImage' => [ // REQUIRED
|
||||||
|
'Bytes' => file_get_contents('C:\Users\Venba\Pictures\wp1833814.jpg'),
|
||||||
|
// 'S3Object' => [
|
||||||
|
// 'Bucket' => 'awsrekonition',
|
||||||
|
// 'Name' => $targetImg,
|
||||||
|
// 'Version' => 'any',
|
||||||
|
// ],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch(AwsException $e){
|
||||||
|
print_r($e->getMessage());
|
||||||
|
//echo "ex";
|
||||||
|
// echo "\n"; .
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createNewBucket($BUCKET_NAME)
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
$result = $this->S3->createBucket(['ACL' => 'private','Bucket' => $BUCKET_NAME]);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
} catch (AwsException $e) {
|
||||||
|
//output error message if fails
|
||||||
|
log_message('ERROR', $e->getMessage());
|
||||||
|
return $e->getMessage();
|
||||||
|
//echo "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function uploadFileToS3Bucket($data)
|
||||||
|
{
|
||||||
|
$result = "";
|
||||||
|
try {
|
||||||
|
|
||||||
|
$result = $this->S3->putObject([
|
||||||
|
'Bucket' => $data['bucket_name'],
|
||||||
|
'Key' => $data['key'],
|
||||||
|
'SourceFile' => $data['sourcefile'],
|
||||||
|
'ContentType' => '*/*',
|
||||||
|
'StorageClass' => 'STANDARD',
|
||||||
|
'ACL'=>'private'
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (AwsException $e)
|
||||||
|
{
|
||||||
|
$result = false;
|
||||||
|
log_message('ERROR',$e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This Function return signed URI of single S3 Object*/
|
||||||
|
public function getSingleObjectInaBucketAsSignedURI($bucket_name,$folder_name,$time = '+5 minutes')//get as singed url
|
||||||
|
{
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// $result = $this->S3->getObject([
|
||||||
|
// 'Bucket' => 'thecucumber',
|
||||||
|
// 'Key' => 'byapi/woodgrass1.jpg'
|
||||||
|
// //'ResponseContentType' => 'image/png'
|
||||||
|
// //'ResponseContentDisposition' => 'attachment; woodgrass1.jpg',
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
$cmd = $this->S3->getCommand('GetObject', [
|
||||||
|
'Bucket' => $bucket_name,
|
||||||
|
'Key' => $folder_name
|
||||||
|
]);
|
||||||
|
|
||||||
|
$request = $this->S3->createPresignedRequest($cmd, $time);
|
||||||
|
$presignedUrl = (string) $request->getUri();
|
||||||
|
}
|
||||||
|
catch(AwsException $e)
|
||||||
|
{
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $presignedUrl;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getS3SingleObj($bucket_name,$folder_name,$time = '+5 minutes')
|
||||||
|
{
|
||||||
|
//echo $time;die();
|
||||||
|
$result = $this->S3->getObject([
|
||||||
|
'Bucket' => $bucket_name,
|
||||||
|
'Key' => $folder_name
|
||||||
|
//'ResponseContentType' => 'image/png'
|
||||||
|
//'ResponseContentDisposition' => 'attachment; woodgrass1.jpg',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// Get List of objetcs as byte(Raw file).
|
||||||
|
public function getAllObjectsInaBucket($bucket_name,$folder_name)
|
||||||
|
{
|
||||||
|
$objects = array();
|
||||||
|
try {
|
||||||
|
$objects = $this->S3->getIterator('ListObjects', [
|
||||||
|
'Bucket' => $bucket_name,
|
||||||
|
'Prefix' => $folder_name
|
||||||
|
]);
|
||||||
|
|
||||||
|
// echo "Keys retrieved!" ;
|
||||||
|
// //print_r($objects);
|
||||||
|
// foreach ($objects as $object) {
|
||||||
|
// print_r($object) ;
|
||||||
|
// }
|
||||||
|
} catch (S3Exception $e) {
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $objects;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Delete an object from the bucket.
|
||||||
|
public function deleteSingleObjFromBucket($bucket,$key)
|
||||||
|
{
|
||||||
|
|
||||||
|
$result = $this->S3->deleteObject([
|
||||||
|
'Bucket' => $bucket,
|
||||||
|
'Key' => $key
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCors($BUCKETNAME)
|
||||||
|
{
|
||||||
|
|
||||||
|
$result = $this->S3->putBucketCors([
|
||||||
|
'Bucket' => $BUCKETNAME,
|
||||||
|
'CORSConfiguration' => [
|
||||||
|
'CORSRules' => [
|
||||||
|
[
|
||||||
|
'AllowedHeaders' => [
|
||||||
|
'*',
|
||||||
|
],
|
||||||
|
'AllowedMethods' => [
|
||||||
|
'PUT',
|
||||||
|
'POST',
|
||||||
|
'DELETE',
|
||||||
|
],
|
||||||
|
'AllowedOrigins' => [
|
||||||
|
'*',
|
||||||
|
],
|
||||||
|
'ExposeHeaders' => [
|
||||||
|
'x-amz-server-side-encryption',
|
||||||
|
],
|
||||||
|
'MaxAgeSeconds' => 3000,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'AllowedHeaders' => [
|
||||||
|
'Authorization',
|
||||||
|
],
|
||||||
|
'AllowedMethods' => [
|
||||||
|
'GET',
|
||||||
|
],
|
||||||
|
'AllowedOrigins' => [
|
||||||
|
'*',
|
||||||
|
],
|
||||||
|
'MaxAgeSeconds' => 3000,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getCORES($BUCKETNAME)
|
||||||
|
{
|
||||||
|
$result = $this->S3->getBucketCors([
|
||||||
|
'Bucket' => $BUCKETNAME]);
|
||||||
|
//////print_r($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function copyS3Object($targetBucket,$sourceBucket,$sourceKeyname,$tagetKeyname)
|
||||||
|
{
|
||||||
|
|
||||||
|
//echo $sourceBucket.'/'.$sourceKeyname;
|
||||||
|
// Copy an object.
|
||||||
|
$res = $this->S3->copyObject([
|
||||||
|
'Bucket' => $targetBucket,
|
||||||
|
'Key' => $tagetKeyname.'/'.$tagetKeyname.'.png',
|
||||||
|
'CopySource' => $sourceBucket.'/'.$sourceKeyname.'/v4MLA2019-01-12-18:01:21.png'
|
||||||
|
]);
|
||||||
|
|
||||||
|
print($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dupSinglePDImages($bucketName,$sourceKey,$targetKey)
|
||||||
|
{
|
||||||
|
//first get all images/s3 obj from source bucket$objects = array();
|
||||||
|
$existingS3Objects = array();
|
||||||
|
$copied_objects = 0;
|
||||||
|
try {
|
||||||
|
|
||||||
|
$existingS3Objects =$this->S3->listObjects(['Bucket' => $bucketName,'Prefix' => $sourceKey]);
|
||||||
|
if(isset($existingS3Objects['Contents']) && count($existingS3Objects['Contents']))
|
||||||
|
{
|
||||||
|
// Perform a batch of CopyObject operations.
|
||||||
|
$batch = array();
|
||||||
|
foreach($existingS3Objects['Contents'] as $obj_key => $obj_vale)
|
||||||
|
{
|
||||||
|
$key = ($obj_vale['Key']);
|
||||||
|
$fulltargetKey = (function() use ($targetKey,$key){
|
||||||
|
$res = '';
|
||||||
|
$t = explode('/',$key);unset($t[0]);
|
||||||
|
foreach ($t as $index => $value) { $res .= (count($t) == ($index+1) ? $value.'/' : $value); }
|
||||||
|
return $targetKey.'/'.$res;
|
||||||
|
|
||||||
|
});
|
||||||
|
$fulltargetKey = $fulltargetKey();
|
||||||
|
//echo $fulltargetKey.'###'.$bucketName.'/'.$key.'~~~';
|
||||||
|
$batch[] = $this->S3->getCommand('CopyObject', [
|
||||||
|
'Bucket' => $bucketName,
|
||||||
|
'Key' => $fulltargetKey,
|
||||||
|
'CopySource' => "$bucketName/$key",
|
||||||
|
'MetadataDirective' => 'REPLACE'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$results = CommandPool::batch($this->S3, $batch);
|
||||||
|
foreach($results as $result) {
|
||||||
|
if ($result instanceof ResultInterface)
|
||||||
|
{
|
||||||
|
$copied_objects++;
|
||||||
|
echo 'DONE';
|
||||||
|
}
|
||||||
|
if ($result instanceof AwsException) {
|
||||||
|
log_message('ERROR','###Error in Batch result - '.$result->getAwsErrorMessage());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception $e)
|
||||||
|
{
|
||||||
|
log_message('ERROR','###Error in executing Copy Batch Operation');
|
||||||
|
log_message('ERROR',$e->getMessage());
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (S3Exception $e)
|
||||||
|
{
|
||||||
|
log_message('ERROR','###Error in getting all exist s3 keys');
|
||||||
|
log_message('ERROR',$e->getMessage());
|
||||||
|
//echo $e->getMessage() . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $copied_objects;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@ -4,7 +4,7 @@ require_once( APPPATH.'/third_party/PHPExcel/Classes/PHPExcel.php');
|
|||||||
|
|
||||||
class Excel extends PHPExcel {
|
class Excel extends PHPExcel {
|
||||||
|
|
||||||
// var $debug = false;
|
var $debug = false;
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user