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
'cdnDomain' => env('BUNNY_STORAGE_CDN_DOMAIN', ''), // your cnd url
41
+
'region' => env('BUNNY_STORAGE_REGION', ''), // region, empty is DE
42
+
'baseHostName' => 'storage.bunnycdn.com', // base host name not changeable
43
+
'storageZone' => env('BUNNY_STORAGE_ZONE', ''), // your storage zone name
44
+
'storageZonePath' => env('BUNNY_STORAGE_ZONE_PATH', ''), // folder in zono
45
+
'accessKey' => env('BUNNY_STORAGE_ACCESS_KEY', ''), // API key for write access
46
+
]
47
+
]
28
48
```
29
49
30
-
Next load it in controllers where you want to use it. To use default config
50
+
For bunny cdn minimal configuration is to have folowing keys configured
31
51
32
-
```php
33
-
public function initialize(): void
34
-
{
35
-
parent::initialize();
36
-
$this->loadComponent('FileUpload.Upload');
37
-
$this->loadComponent('FileUpload.Dowmload'); // in case you wan to download files
38
-
}
52
+
```ini
53
+
BUNNY_STORAGE_ACCESS_KEY=
54
+
BUNNY_STORAGE_CDN_DOMAIN=
55
+
BUNNY_STORAGE_ZONE=
39
56
```
40
57
41
-
## Using local storage
58
+
If you need/want nginx to server your static files without PHP set `STORAGE_LOCAL_STORAGE_PATH` location to whe webroot folder.
42
59
43
-
Commands above are loaded with default configuration:
44
-
- Using Local filesystem: type is set to `local`
45
-
- Data are stored in `sotrage` folder in root of your application - This folder is not public and cannot be served directly from webserver. You need to use `DownloadComponent` to get files
46
-
- Field name for uploading files is `uploaded_file`
47
-
- Allowed are all file types
60
+
Load plugin with adding
48
61
49
62
```php
50
-
public function initialize(): void
51
-
{
52
-
parent::initialize();
53
-
$this->loadComponent('FileUpload.Upload', [
54
-
'fieldName' => 'your_form_file_field',
55
-
'storagePath' => 'path_to_storage',
56
-
'allowedFileTypes' => '*'
57
-
]);
58
-
}
63
+
$this->addPlugin('FileUpload'); // in your Application.php bootstrap function
59
64
```
60
65
61
-
For `allowedFileTypes` use `'allowedFileTypes' => '*'` for all file types or `'allowedFileTypes' => ['type1', 'type2']` for your expected file types. If file have not allowed type Component will throw `Cake\Http\Exception\HttpException`.
62
-
63
-
Using local storage (default option) you can use default config but do not forge to change allowed file types and form field nam from which you uploading file to server.
64
-
65
-
## Using S3 storage
66
-
67
-
For S3 storage configuration is pretty same as configuration above, but you have to change type to `s3` instead of `local` which is default as follows
66
+
or you can add your plugin with `plugins.php` config file
68
67
69
68
```php
70
-
public function initialize(): void
71
-
{
72
-
parent::initialize();
73
-
$this->loadComponent('FileUpload.Upload', [
74
-
'fieldName' => 'your_form_file_field',
75
-
'storagePath' => 'bucket_name',
76
-
'storage_type' => 's3'
77
-
]);
78
-
}
69
+
return [
70
+
// .. your other plugins
71
+
'FileUpload' => [],
72
+
];
79
73
```
80
74
81
-
:exclamation: Dont forget to change configuration for `DownloadComponent` too if you planing using it.
82
-
83
-
Next add configuration for s3 server to your config file `app_local.php` for example as follows:
75
+
Loading components
84
76
85
77
```php
86
-
'S3' => [
87
-
'version' => 'latest',
88
-
'region' => 'us-east-1',
89
-
'endpoint' => 'http://cake_minio:9000',
90
-
'use_path_style_endpoint' => true,
91
-
'credentials' => [
92
-
'key' => 'minioadmin',
93
-
'secret' => 'minioadmin',
94
-
],
95
-
]
96
-
```
78
+
$config = Configure::read('Storage.local'); // or Storage.bunny
97
79
98
-
Config above is for using minio with my [CakePHP starte kit](https://github.com/MayMeow/cakephp-starter-kit). Change it for your needs.
80
+
// or by setting it with .env STORAGE_DEFAULT_STORAGE_TYPE
:memo: Note that the function above will read content of file and you then need to use response to push it to the viewer. If you want to do it without using PHP you will need to get URL of file and if you using local storage manager your folder need to be in webrootfolder.
156
104
157
-
*[x] Configurable field name
158
-
*[x] Configurable path to storage
159
-
*[x] Allowed file types
160
-
*[x] Add S3 Support
161
-
*[ ] Multiple file upload
162
-
*[ ] File Size
105
+
```php
106
+
$file->get('storagePath'); // local: /patht/to/sorage or bunny: https://cdn.your.tld/path/to/folder/
107
+
// combine it with filename from your database go download it
108
+
```
163
109
164
-
💡 If you have more ideas then you can post issue on porect's GitHub page.
0 commit comments