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
* ADD `LocalStorageManager` and `S3StorageManager` which handling upload and download files from storage
11
+
* ADD New configuration for `S3` client (for more informations check README)
12
+
* ADD `StorageConfigInterface`, `StorageManagerInterface` and `StoredFileInterface`
13
+
* UPDATE Return type for `getFile()` was changed to`\FileUpload\File\StoredFileInterface` from `\Psr\Http\Message\UploadedFileInterface` Which returning more informations about file
14
+
* UPDATE `UploadComponent::getFile()` from now can throw `HttpException` in case there is `Not supported storage type` in configuration
@@ -41,10 +34,17 @@ public function initialize(): void
41
34
{
42
35
parent::initialize();
43
36
$this->loadComponent('FileUpload.Upload');
37
+
$this->loadComponent('FileUpload.Dowmload'); // in case you wan to download files
44
38
}
45
39
```
46
40
47
-
Or you can change them
41
+
## Using local storage
42
+
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
48
48
49
49
```php
50
50
public function initialize(): void
@@ -60,40 +60,95 @@ public function initialize(): void
60
60
61
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
62
63
-
Usage in function
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
68
+
69
+
```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
+
}
79
+
```
80
+
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:
64
84
65
85
```php
66
-
public function add()
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
+
```
97
+
98
+
Config above is for using minio with my [CakePHP starte kit](https://github.com/MayMeow/cakephp-starter-kit). Change it for your needs.
99
+
100
+
101
+
## Uploading files
102
+
103
+
104
+
```php
105
+
/**
106
+
* @throws \HttpException
107
+
* @return \Cake\Http\Response|null|void
108
+
*/
109
+
public function upload()
67
110
{
68
-
$file = $this->Files->newEmptyEntity();
111
+
$uploadForm = new UploadForm();
69
112
70
113
if ($this->request->is('post')) {
71
-
72
-
// you can use try catch to show Flash instead of error page
0 commit comments