承接 groovili/rest-uploader-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Latest Stable Version Total Downloads License

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:

  1. rest_uploader.file.preUpload
  2. rest_uploader.file.postUpload
  3. rest_uploader.file.preDownload
  4. rest_uploader.file.preDelete
  5. rest_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 我们能提供哪些服务?
定制开发 / 二次开发

基于 groovili/rest-uploader-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 205
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-08