Skip to content

Commit

Permalink
Merge pull request #25 from publiux/development
Browse files Browse the repository at this point in the history
Added ability to specify upload folder prefix when pushing assets.
  • Loading branch information
publiux authored Oct 30, 2017
2 parents 43a6538 + 66e7514 commit 1b1d6bf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,16 @@ 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
```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

Expand Down
6 changes: 4 additions & 2 deletions src/Publiux/laravelcdn/Providers/AwsS3Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AwsS3Provider extends Provider implements ProviderInterface
'version' => null,
'region' => null,
'buckets' => null,
'upload_folder' => '',
'http' => null,
'acl' => 'public-read',
'cloudfront' => [
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -413,4 +415,4 @@ public function __get($attr)
{
return isset($this->supplier[$attr]) ? $this->supplier[$attr] : null;
}
}
}
19 changes: 19 additions & 0 deletions src/config/cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''),

/*
|--------------------------------------------------------------------------
Expand Down

0 comments on commit 1b1d6bf

Please sign in to comment.