-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to upload directly to s3
- Loading branch information
muruganstr
committed
Nov 16, 2016
1 parent
4fdc9eb
commit 0cfb395
Showing
2 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0cfb395
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m using Tinify with my Laravel application. Part of my deployment process is to optimize my configuration environment by using php artisan config:cache. This speeds my app’s load time as well as access to configuration variables. Unfortunately, one of the side effects of using this is that the env(‘’) function no longer works to retrieve environment variable settings. You instead need to create a file in /config and pre-load all of your .env settings. Here’s the best explanation I could find of the procedure: https://scotch.io/tutorials/how-to-use-laravel-config-files
The TinifyService class uses env(‘’) in its constructor. Since I’m using php artisan config:cache, this always returns a null string.
So … what I’m asking is if you could modify your code to include a config/tinify.php file that pulls in the S3_KEY, S3_SECRET, S3_REGION from the .env file. You would then need to load the .env value in the new config/tinify.php file and modify the TinifyService class to use config(‘tinify.s3_key’), config(‘tinify.s3_secret’), config(‘tinify.s3_region’) (or similar).
This approach would then work correctly whether the user implements the config cache or not.
Something similar to below:
Current TinifyService constructor
class TinifyService {
Proposed TinifyService constructor
class TinifyService {
/**
* Get api key from env, fail if any are missing.
* Instantiate API client and set api key.
*
* @throws Exception
*/
public function __construct() {
$this->apikey = config(‘tinify.apikey’);
if(!$this->apikey) {
throw new \InvalidArgumentException('Please set TINIFY_APIKEY environment variables.');
}
$this->client = new Tinify();
$this->client->setKey($this->apikey);
current config/tinify.php
env(‘TINIFY_APIKEY’), ]; Proposed config/tinify.php env(‘TINIFY_APIKEY’), "s3_key" => env('S3_KEY'), "s3_secret" => env('S3_SECRET'), "s3_region" => env('S3_REGION'), ];