You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 5, 2022. It is now read-only.
There is now an exception throw if a listener can't work with a specific adapter. Also I've introduced a new BaseListener that doesn't have any restrictions on which adapter it will take. In theory you can use it with any storage backend as long as the path it builds for the files is compatible with your chosen storage backend.
A new shell command has been introduced to store a file via command line.
The Quick Start tutorial has been updated as well.
Copy file name to clipboardExpand all lines: docs/Tutorials/Quick-Start.md
+49-23Lines changed: 49 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -18,21 +18,26 @@ app/Config/file_storage.php
18
18
19
19
There is a good amount of code to be added to prepare everything. In theory you can put all of this in bootstrap as well but to keep things clean it is recommended to put all of this in a separate file.
20
20
21
+
This might look like a lot things to do but when this is done storing the files will work immediately and you have a *very* flexible and powerful storage system configured.
22
+
21
23
```php
22
-
use Aws\S3;
23
-
use Burzum\FileStorage\Event\ImageProcessingListener;
24
-
use Burzum\FileStorage\Event\S3StorageListener;
25
-
use Burzum\FileStorage\Lib\FileStorageUtils;
26
-
use Burzum\FileStorage\Lib\StorageManager;
24
+
use Aws\S3\S3Client;
25
+
use Burzum\FileStorage\Storage\Listener\BaseListener;
26
+
use Burzum\FileStorage\Storage\StorageUtils;
27
+
use Burzum\FileStorage\Storage\StorageManager;
27
28
use Cake\Core\Configure;
28
29
use Cake\Event\EventManager;
29
30
30
-
// Attach the S3 Listener to the global EventManager
31
-
$listener = new S3StorageListener();
32
-
EventManager::instance()->on($listener);
33
-
34
-
// Attach the Image Processing Listener to the global EventManager
35
-
$listener = new ImageProcessingListener();
31
+
// Instantiate a storage event listener
32
+
$listener = new BaseListener(
33
+
'imageProcessing' => true, // Required if you want image processing!
34
+
'pathBuilderOptions' => [
35
+
// Preserves the original filename in the storage backend.
36
+
// Otherwise it would use a UUID as filename by default.
37
+
'preserveFilename' => true
38
+
]
39
+
);
40
+
// Attach the BaseListener to the global EventManager
// This is very important! The hashes are needed to calculate the image versions!
68
-
FileStorageUtils::generateHashes();
69
-
70
-
// Optional, lets use the AwsS3 adapter here instead of local
71
-
$S3Client = \Aws\S3\S3Client::factory([
72
-
'key' => 'YOUR-KEY',
73
-
'secret' => 'YOUR-SECRET'
74
-
]);
73
+
StorageUtils::generateHashes();
74
+
75
+
// Lets use the Amazon S3 adapter here instead of the default `Local` config.
76
+
// We need to pass a S3Client instance to this adapter to make it work
77
+
$S3Client = new S3Client([
78
+
'version' => 'latest',
79
+
'region' => 'eu-central-1',
80
+
'credentials' => [
81
+
'key' => 'YOUR-AWS-S3-KEY-HERE',
82
+
'secret' => 'YOUR-SECRET-HERE'
83
+
]
84
+
]);
75
85
76
-
// Configure the Gaufrette adapter through the StorageManager
77
-
StorageManager::config('S3Image', [
78
-
'adapterOptions' => [
86
+
// Configure the S3 adapter instance through the StorageManager
87
+
StorageManager::config('S3', [
88
+
'adapterOptions' => array(
79
89
$S3Client,
80
-
'YOUR-BUCKET-NAME',
90
+
'YOUR-BUCKET-NAME-HERE', // Bucket
81
91
[],
82
92
true
83
-
],
93
+
),
84
94
'adapterClass' => '\Gaufrette\Adapter\AwsS3',
85
95
'class' => '\Gaufrette\Filesystem'
86
96
]);
87
97
```
88
98
99
+
If you did everything right you can now run this command from your app:
100
+
101
+
```sh
102
+
bin/cake storage store <some-file-to-store-here> --adapter S3
103
+
```
104
+
105
+
If you did everything right your should see some output like this:
106
+
107
+
If you're not familiar with the CakePHP shell and running into problems with the shell, not the plugin itself, please [read this](http://book.cakephp.org/3.0/en/console-and-shells.html) first!
0 commit comments