Download the PHP package ccasanovas/cake-s3upload without Composer
On this page you can find all versions of the php package ccasanovas/cake-s3upload. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ccasanovas/cake-s3upload
More information about ccasanovas/cake-s3upload
Files in ccasanovas/cake-s3upload
Package cake-s3upload
Short Description S3UploadSDK plugin for CakePHP
License MIT
Informations about the package cake-s3upload
S3UploadSDK plugin para CakePHP
Este plugin permite rapidamente hacer que una Table suba archivos a un bucket de AWS S3, mediante el behavior proporcionado.
Changelog
Fecha: 2020-11-24
- Arreglado alerta de deprecated en behavior
Fecha: 2019-03-25
- Arreglado bug que hacia que los archivos se subieran a S3 como texto plano
Fecha: 2018-11-20
- Agregada funcionalidad para eliminar archivos cuando están en la misma tabla
Fecha: 2018-10-11
- Reescrita la documentación
Documentación
Funcionalidades
Implementadas:
- Incluye un behavior para las tablas que deban subir archivos, S3UploadSDK, con las siguientes funcionalidades:
- Sube archivos al bucket de s3 configurado
- Almacena en la base de datos los campos de metadatos asi como también la URL completa del archivo.
- Permite fácilmente configurar el archivo a subir como sólo imagen
- Provee varios validadores preconfigurados para integrarlos rapidamente
- Permite togglear para que los archivos se suban localmente
- Método de utilidad para eliminar archivos de la tabla sin borrar el row completo.
Pendientes:
- Permitir configurar varios buckets a la vez
Instalación
Para obtener el plugin con composer se requiere agregar a composer.json
lo siguiente:
- Al objeto
"require"
, agregar el plugin:"ccasanovas/cake-s3upload": "dev-master"
- Al arreglo de
"repositories"
agregar el objeto: - correr
composer update
NOTA: asegurarse de tener los permisos de acceso/deploy correctos en el repositorio.
Una vez instalado el plugin en el repositorio se puede agregar a las tablas necesarias el behavior:
Estructura
Ccasanovas\S3UploadSDK\Model\Behavior\AwsS3UploadBehavior
- public initialize(array $config)
- Comprueba que las variables de configuracion necesarias estén disponibles y sean correctos
- Construye y configura el cliente para interactuar con S3
- Le agrega el adaptador de s3 y un path por defecto a todos los campos configurados en el modelo
- Una vez procesadas las configuraciones de los campos, agrega el behavior 'Josegonzalez/Upload.Upload' a la Table y se las pasa
- public buildValidator(Event $event, Validator $validator, $name)
- Para cada uno de los campos configurados, agrega reglas de validación estandar para el tipo de archivo
- Incluye las siguientes reglas:
- fileUnderPhpSizeLimit
- fileUnderFormSizeLimit
- fileCompletedUpload
- fileFileUpload
- fileSuccessfulWrite
- Además, si el campo está configurado con
['images_only' => true]
, agrega validación para el mimeType, aceptando solo los siguientes:- image/gif
- image/png
- image/jpg
- image/jpeg
- public afterRules(Event $event, EntityInterface $entity, ArrayObject $options, $result, $operation)
- Si los campos de alto y ancho están configurados, intenta obtener esas propiedades del archivo y popular esos campos
- public beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
- almancena la url completa del archivo subido a S3 en el campo de url
- Si se está borrando el archivo, se encarga de limpiar los campos relacionados también (dir, type, size, etc)
- public deleteFile($id, $field)
- Método de utilidad para borrar el $field de la entidad. Junto con el beforeSave, se puede llamar por ejemplo a
$this->Products->deleteFile($product_id, 'file_name');
y se borrará el contenido defile_name
y sus campos relacionados (por ej: file_dir, file_size, file_type, etc).
- Método de utilidad para borrar el $field de la entidad. Junto con el beforeSave, se puede llamar por ejemplo a
Variables de configuracion
Las variables de configuración se guardan en el arreglo de configuración de la aplicación al igual que el resto de las configuraciones (config/app.php
por defecto).
Las configuraciones disponibles son:
Testing
//TODO
All versions of cake-s3upload with dependencies
josegonzalez/cakephp-upload Version ^6.0.0
league/flysystem-aws-s3-v3 Version 2.*