From c7617dfc2046cc07e210dd0d6e4026b2f6f92ef5 Mon Sep 17 00:00:00 2001 From: Raul Ruiz Date: Mon, 30 Oct 2017 06:57:32 -0400 Subject: [PATCH 1/5] Update AwsS3Provider.php --- src/Publiux/laravelcdn/Providers/AwsS3Provider.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Publiux/laravelcdn/Providers/AwsS3Provider.php b/src/Publiux/laravelcdn/Providers/AwsS3Provider.php index 6ec54dc..8be8982 100644 --- a/src/Publiux/laravelcdn/Providers/AwsS3Provider.php +++ b/src/Publiux/laravelcdn/Providers/AwsS3Provider.php @@ -49,6 +49,7 @@ class AwsS3Provider extends Provider implements ProviderInterface 'version' => null, 'region' => null, 'buckets' => null, + 'upload_folder' => '' 'http' => null, 'acl' => 'public-read', 'cloudfront' => [ @@ -138,6 +139,7 @@ public function init($configurations) 'cloudfront' => $this->default['providers']['aws']['s3']['cloudfront']['use'], 'cloudfront_url' => $this->default['providers']['aws']['s3']['cloudfront']['cdn_url'], 'http' => $this->default['providers']['aws']['s3']['http'], + 'upload_folder' => $this->default['providers']['aws']['s3']['upload_folder'] ]; // check if any required configuration is missed @@ -180,7 +182,7 @@ public function upload($assets) // the bucket name 'Bucket' => $this->getBucket(), // the path of the file on the server (CDN) - 'Key' => str_replace('\\', '/', $file->getPathName()), + 'Key' => $this->supplier['upload_folder'] . str_replace('\\', '/', $file->getPathName()), // the path of the path locally 'Body' => fopen($file->getRealPath(), 'r'), // the permission of the file @@ -413,4 +415,4 @@ public function __get($attr) { return isset($this->supplier[$attr]) ? $this->supplier[$attr] : null; } -} \ No newline at end of file +} From a1ec48c5eab55f33ff714aad9769572206ad517e Mon Sep 17 00:00:00 2001 From: Raul Ruiz Date: Mon, 30 Oct 2017 07:00:09 -0400 Subject: [PATCH 2/5] Update AwsS3Provider.php --- src/Publiux/laravelcdn/Providers/AwsS3Provider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Publiux/laravelcdn/Providers/AwsS3Provider.php b/src/Publiux/laravelcdn/Providers/AwsS3Provider.php index 8be8982..7101a7a 100644 --- a/src/Publiux/laravelcdn/Providers/AwsS3Provider.php +++ b/src/Publiux/laravelcdn/Providers/AwsS3Provider.php @@ -49,7 +49,7 @@ class AwsS3Provider extends Provider implements ProviderInterface 'version' => null, 'region' => null, 'buckets' => null, - 'upload_folder' => '' + 'upload_folder' => '', 'http' => null, 'acl' => 'public-read', 'cloudfront' => [ From e7e05690a4905405a0a4eba47ec1c042a3ace479 Mon Sep 17 00:00:00 2001 From: Raul Ruiz Date: Mon, 30 Oct 2017 07:45:04 -0400 Subject: [PATCH 3/5] Update cdn.php --- src/config/cdn.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/config/cdn.php b/src/config/cdn.php index f80d115..8de77ee 100644 --- a/src/config/cdn.php +++ b/src/config/cdn.php @@ -117,6 +117,25 @@ // 'your-js-bucket-name-here' => ['public/js'], // 'your-css-bucket-name-here' => ['public/css'], ], + + /* + |-------------------------------------------------------------------------- + | CDN Bucket Upload Folder Prefix + |-------------------------------------------------------------------------- + | + | You can specify a prefix for files when they are pushed/uploaded to S3. + | For example, if you want to have your files uploaded into a folder in the + | called 'webassets', you would specify 'webassets/'. + | + | When the command 'php artisan cdn:push' is run, your assets will be + | uploaded to S3, but will be placed inside this folder. + | + | If you do not wish to set this prefix, leave an empty string as the value. + | + | NOTE: YOUR FOLDER NAME PREFIX MUST END WITH A TRAILING SLASH, e.g. 'folder/' + | + */ + 'upload_folder' => env('AWS_CDN_ASSET_UPLOAD_FOLDER', ''), /* |-------------------------------------------------------------------------- From 3c32d5b5ed9117fa751662f8bb8603ec084504cf Mon Sep 17 00:00:00 2001 From: Raul Ruiz Date: Mon, 30 Oct 2017 07:46:59 -0400 Subject: [PATCH 4/5] Update readme.md --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index 11fe493..c07bc50 100644 --- a/readme.md +++ b/readme.md @@ -210,6 +210,9 @@ Upload assets to CDN ```bash php artisan cdn:push ``` + +You can specify a folder upload prefix in the cdn.php config file. Your assets will be uploaded into that folder on S3. + #### Empty Delete assets from CDN From 94fd9af6764391d126a2eb729c5302712a0819e2 Mon Sep 17 00:00:00 2001 From: Raul Ruiz Date: Mon, 30 Oct 2017 07:49:38 -0400 Subject: [PATCH 5/5] Added warning about empty command. --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index c07bc50..d33ebb5 100644 --- a/readme.md +++ b/readme.md @@ -219,6 +219,7 @@ Delete assets from CDN ```bash php artisan cdn:empty ``` +CAUTION: This will erase your entire bucket. This may not be what you want if you are specifying an upload folder when you push your assets. #### Load Assets