groovili/rest-uploader-bundle
Composer 安装命令:
composer require groovili/rest-uploader-bundle
包简介
A Symfony bundle to handle file upload and management for REST API
关键字:
README 文档
README
A Symfony bundle for file upload and management for REST API.
Provides File entity, rest_uploader.manager,rest_uploader.validator services, RestFileType and list of events to subscribe:
rest_uploader.file.preUploadrest_uploader.file.postUploadrest_uploader.file.preDownloadrest_uploader.file.preDeleterest_uploader.file.preGetPath
Examples can be found in examples section below.
Installation
Require the groovili/rest-uploader-bundle package in your composer.json and update your dependencies.
composer require groovili/rest-uploader-bundle
Add the RestUploaderBundle to your application's kernel:
public function registerBundles() { $bundles = [ // ... new Groovili\RestUploaderBundle\RestUploaderBundle(), // ... ]; // ... }
Please notice that csrf_protection should be false to use RestFileType.
Configuration
The public_dir and private_dir are path strings from app folder.
If not exist, would be added automatically. This parameters should be only strings.
allowed_extensions is array of strings with allowed file extensions.
file_max_size is integer number in MB, which would be maximum limit.
Configuration which provided below is default for this bundle:
rest_uploader: public_dir: '../web/files' private_dir: '../private' allowed_extensions: [] file_max_size: 25
Examples
RestFileType for file upload
<?php /** @var @UploadedFile $upload */ $upload = $request->files->get('file'); if (isset($upload)) { $form = $this->createFormBuilder() ->add('file', RestFileType::class, [ 'allow_delete' => true, 'validate_extensions' => true, 'validate_size' => true, 'private' => false, ]) ->getForm(); $form->handleRequest($request); $clearMissing = $request->getMethod() != 'PATCH'; $form->submit(['file' => $upload], $clearMissing); $data = $form->getData(); if (isset($data['file'])) { /** @var File $file */ $file = $data['file']; $em = $this->getDoctrine()->getManager(); $em->persist($file); $em->flush(); } }
RestFileType submit of existing entity
<?php /** * $file = ['file' => ['id' => 8]] */ $file = json_decode($request->getContent(), true); $form = $this->createFormBuilder() ->add('file', RestFileType::class, [ 'allow_delete' => true, 'validate_extensions' => true, 'validate_size' => true, 'private' => false, ]) ->getForm(); $form->handleRequest($request); $clearMissing = $request->getMethod() != 'PATCH'; $form->submit($file , $clearMissing);
RestFileType delete of existing entity
<?php /** * $file = ['file' => ['id' => 8, 'delete' => true]] */ $file = json_decode($request->getContent(), true); $form = $this->createFormBuilder() ->add('file', RestFileType::class, [ 'allow_delete' => true, 'validate_extensions' => true, 'validate_size' => true, 'private' => false, ]) ->getForm(); $form->handleRequest($request); $clearMissing = $request->getMethod() != 'PATCH'; $form->submit($file , $clearMissing); $em = $this->getDoctrine()->getManager(); $em->flush();
Upload and validate file via service
<?php /** @var @UploadedFile $upload */ $upload = $request->files->get('file'); if (isset($upload)) { $validator = $this->container->get('rest_uploader.validator'); $uploader = $this->container->get('rest_uploader.manager'); if ($validator->isExtensionAllowed($upload) && $validator->isSizeValid($upload)){ /** @var File $file */ $file = $uploader->upload($upload, false); } }
Add bundle routing to your routing.yml
file: resource: '@RestUploaderBundle/Resources/config/routing.yml' type: yaml
groovili/rest-uploader-bundle 适用场景与选型建议
groovili/rest-uploader-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 205 次下载、GitHub Stars 达 6, 最近一次更新时间为 2018 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「file」 「rest」 「upload」 「validation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 groovili/rest-uploader-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 groovili/rest-uploader-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 groovili/rest-uploader-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
The bundle for easy using json-rpc api on your project
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Bundle Symfony DaplosBundle
Laravel Media Popup to upload/view the files
统计信息
- 总下载量: 205
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-08