-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add documentation and only load example endpoints when debug is set t…
…o true
- Loading branch information
Andres Campanario
committed
Apr 8, 2024
1 parent
7917862
commit 2153c0f
Showing
6 changed files
with
200 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
## CakePHP | ||
|
||
CakePHP installation and configuration example using Docker | ||
|
||
``` | ||
$> composer create-project --prefer-dist cakephp/app:~5 uppy_app | ||
$> cd uppy_app | ||
$> cp config/app_local.example.php config/app_local.php | ||
``` | ||
|
||
## Docker | ||
|
||
create docker-compose.yml file as | ||
``` | ||
version: '3' | ||
services: | ||
psql13: | ||
image: postgres:13 | ||
container_name: uppy-app-postgres13 | ||
volumes: | ||
- ./tmp/data/inertia-postgres13__db:/var/lib/postgresql:delegated | ||
environment: | ||
- POSTGRES_USER=my_app | ||
- POSTGRES_PASSWORD=secret | ||
- POSTGRES_DB=my_app | ||
- PGUSER=my_app | ||
- PGDATABASE=my_app | ||
- PGPASSWORD=secret | ||
ports: | ||
- '7432:5432' | ||
cakephp: | ||
image: webdevops/php-nginx:8.1 | ||
container_name: uppy-app-cakephp | ||
working_dir: /application | ||
volumes: | ||
- ./:/application:cached | ||
- ~/.ssh:/home/application/.ssh:ro | ||
environment: | ||
- WEB_DOCUMENT_ROOT=/application/webroot | ||
- DATABASE_URL=postgres://my_app:secret@uppy-app-postgres13:5432/my_app | ||
ports: | ||
- "9099:80" | ||
``` | ||
|
||
launch container | ||
|
||
``` | ||
$> docker-compose up -d | ||
``` | ||
|
||
go to http://localhost:9099/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
## Configure | ||
|
||
To configure the plugin first copy the base configuration to your project | ||
|
||
``` | ||
$> cp vendor/cakedc/cakephp-uppy/config/uppy.php config/uppy.php | ||
``` | ||
|
||
Then run migration to create table *uppy_files* where save data for files uploaded | ||
|
||
``` | ||
$> bin/cake migrations migrate -p CakeDC/Uppy | ||
``` | ||
|
||
Note: you can change the name of this table in the configuration file *config/uppy.php* | ||
|
||
## Configuration file *config/uppy.php* | ||
|
||
By default, when debug is set to true the plugin will add a number of routes to your application `/uppy/files` in order to | ||
upload and view the uploaded files. You should protect these endpoints in case your application requires | ||
authentication to upload or manage files. Failing to do so would allow an authenticated user to *upload* files | ||
to your application. | ||
|
||
### Default uppy config file: | ||
|
||
```php | ||
<?php | ||
|
||
return [ | ||
'Uppy' => [ | ||
'Props' => [ | ||
'usersModel' => 'Users', | ||
'deleteFileS3' => true, | ||
'tableFiles' => 'uppy_files', | ||
], | ||
'AcceptedContentTypes' => [ | ||
'application/pdf', | ||
'image/png', | ||
], | ||
'AcceptedExtensions' => [ | ||
'pdf', | ||
'png', | ||
], | ||
/* | ||
* S3 configuration to manage files | ||
*/ | ||
'S3' => [ | ||
'contants' => [ | ||
'lifeTimeGetObject' => '+20 minutes', | ||
'lifeTimePutObject' => '+5 minutes', | ||
], | ||
'config' => [ | ||
'version' => 'latest', | ||
'region' => filter_var(env('S3_REGION', null)), | ||
'endpoint' => filter_var(env('S3_END_POINT', null)), | ||
'credentials' => [ | ||
'key' => filter_var(env('S3_KEY', null)), | ||
'secret' => filter_var(env('S3_SECRET', null)), | ||
], | ||
], | ||
'bucket' => filter_var(env('S3_BUCKET')), | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
- usersModel = is the alias name used in you app | ||
- deleteFileS3 = if the record of the file in the database is deleted and it's marked true, the deletion is launched in the S3 deposit | ||
- tableFiles = name of table used to store file data, default is `uppy_files` | ||
- AcceptedContentTypes = list of content-type stored in S3 and saved in database | ||
- AcceptedExtensions = list of file extensions stored in S3 and saved in database | ||
- lifeTimeGetObject = life time generated link to access file in S3 | ||
- lifeTimePutObject = life time generated link to post file in S3 | ||
- region = configured region S3 | ||
- endpoint = endpoint server to PUT/POST/GET S3 files | ||
- key = S3 account key | ||
- secret = S3 account secret | ||
- bucket = bucket name | ||
|
||
Enpoints | ||
------- | ||
|
||
- /uppy/files/sign = sign with credentials and return signed url to upload file in S3 directly in front | ||
- /uppy/files/save = save register just uploaded in database with correct S3 path | ||
- /uppy/files/delete = delete register in database, if Uppy.Props.deleteFileS3 is true remove from S3 | ||
- /uppy/files/view = sign with credentials and return signed url to access file in S3 directly in front | ||
|
||
Sample | ||
------- | ||
|
||
- /uppy/files = list of files in database and link to view/delete in S3 | ||
- /uppy/files/add = example uppy upload file to configured S3 and save data relationed in database | ||
- /uppy/files/drag = example uppy drag and upload multiple file, using Dashboard to configured S3 and save data relationed in database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Installation | ||
|
||
Install plugin via command line: | ||
|
||
``` | ||
$> composer require cakedc/cakephp-uppy | ||
``` | ||
|
||
## Configuration | ||
|
||
Once installed enable it in *src/Application.php*, adding at the bottom of bootstrap function: | ||
|
||
``` | ||
$this->addPlugin('CakeDC/Uppy'); | ||
``` | ||
|
||
or type in command line | ||
|
||
``` | ||
$> bin/cake plugin load CakeDC/Uppy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Home | ||
==== | ||
The **Uppy** Plugin integrate https://github.com/transloadit/uppy to upload files directly to a configured S3 usign a signature, and in the callback response save data related to files uploaded in database. | ||
|
||
The plugin is thought as a base to extend and use your app specific controllers and views from. | ||
|
||
That it works out of the box doesn't mean it is thought to be used exactly like it is but to provide you a kick start. | ||
|
||
Documentation | ||
------------- | ||
|
||
* [CakePHP Docker](Documentation/CakePHP-Docker.md) (optional) | ||
* [Install](Documentation/Installation.md) | ||
* [Configure as Use](Documentation/Configure.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters