PHP code example of epiphanyinfotech / laravel-aws-custom-policy-url-signer

1. Go to this page and download the library: Download epiphanyinfotech/laravel-aws-custom-policy-url-signer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

epiphanyinfotech / laravel-aws-custom-policy-url-signer example snippets


// Add Namespace in Controller
use EpiphanyInfotech\CustomPolicyUrl\CustomPolicyUrl as AWSURL;

/*
 * Instantiate the class and pass the array with values matching 
 * the path of the media files in the AWS S3 Bubket
 */

        $key_id = config('aws-custom-policy-url.KEY-ID');
		
    	$aws_private_key = config('aws-custom-policy-url.AWS-PRIVATE-KEY');
    	
    	$path_arr = array('sample_5mb.mp4','sample_3mb.mp4'); // get the sample files either from your own DB or changing the storage config to s3 bucket and fetching the list of files. Ref.: (https://laravel.com/docs/8.x/filesystem#retrieving-files)

     	$aws_obj = New AWSURL($key_id, $aws_private_key);
    	$get_signed_urls = $aws_obj->getSignedUrls($path_arr);


return [
    /*
     * The cloudfront public keys id. Identifies the CloudFront key pair associated to the trusted signer which validates signed URLs.
     * To create a key, refer: https://console.aws.amazon.com/cloudfront/v3/home?region=us-east-2#/publickey
     * Make sure to replace region=us-east-2 with your region
     */
    'KEY-ID' => env("AWS_KEY_ID", NULL),

    /*
     * The private key used to sign all URLs. Make sure it's secured and not accessible to public. Enter absolute path in the .env file
     */
    "AWS-PRIVATE-KEY" => env("AWS_PRIVATE_KEY_FILEPATH", NULL),

    /*
     * The IP address of the client making the GET request. For further info, visit: (https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-custom-policy.html) and search for - "IpAddress (Optional)"
     */
    "CLIENT_IP" => env("AWS_CLIENT_IP", NULL),,

    /*
     * Your CloudFront domain URL. To check your cloudfront domain, visit: (https://console.aws.amazon.com/cloudfront/v3/home?region=us-east-2#/distributions)
	 * Make sure to replace region=us-east-2 with your region.
	 * The "Domain Name" is your URL. If you have configured cloudfront to use the custom domain, then enter that.
     */
    "AWS_URL" => env("AWS_URL", NULL),

];

php artisan vendor:publish --provider="EpiphanyInfotech\CustomPolicyUrl\CustomPolicyUrlServiceProvider"