定制 avtonom/media-storage-client-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

avtonom/media-storage-client-bundle

Composer 安装命令:

composer require avtonom/media-storage-client-bundle

包简介

Symfony media client bundle for uploading (sending) files and images to a remote server deployed on SonataMediaBundle

README 文档

README

Symfony media client bundle for uploading (sending) files and images to a remote server deployed on SonataMediaBundle

Page bundle: https://github.com/Avtonom/media-storage-client-bundle

Run the following in your project root, assuming you have composer set up for your project

composer.phar require avtonom/media-storage-client-bundle ~1.2

Switching ~1.2 for the most recent tag.

Add the bundle to app/AppKernel.php

$bundles(
    ...
    new Sensio\Bundle\BuzzBundle\SensioBuzzBundle(),
    new Avtonom\MediaStorageClientBundle\AvtonomMediaStorageClientBundle(),
    ...
);

Configuration options (parameters.yaml):

parameters:
    avtonom.media_storage_client:
        clients:
            client_name_url:
                base_url: http://demo.com
                add_media_url: /app_dev.php/api/providers/sonata.media.provider.url/media
            client_name_url:
                base_url: http://demo.com
                add_media_url: /app_dev.php/api/providers/sonata.media.provider.file/media
        urls:
            base_url: http://demo.com
            get_media_by_reference_full_url: /app_dev.php/api/media/referencefull
        listener:
            interfaces: ['Bundle\Model\EntityInterface1', 'Bundle\Model\EntityInterface2']
            change_field: my_change_field
            ignored_domains: ['s.dev.demo.com', 's.prod.demo.com']
            client: client_name_url
            context: context
        logging_level: 100

[Optionally] Configuration bower (\web\bower.json) to file upload:


"blueimp-file-upload-node": "*"

[Optionally] File js to file upload (for example: \src\Bundle\Resources\views\standard_layout.html.twig): This example uses a library of x-editable (http://vitalets.github.io/x-editable/).

{% block javascripts %}
    {{ parent() }}
    {% javascripts
        '@AvtonomMediaStorageClientBundle/Resources/public/js/actions.js'
    %}
        <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

Use alternative number 1: block to add a reference to the file

<a href="{{ mediaReferenceFull }}" class="btn btn-info btn-xs x-editable-update-after-save" target="_blank" data-content-text="%s &nbsp;<i class='fa fa-external-link'></i>" {% if mediaReferenceFull is empty %}style="display: none"{% endif %}>
    {% if mediaReferenceFull is not empty %}
        {% set media = media_get(mediaReferenceFull) %}
        {% if media is ProxyMediaInterface %}
            {{ media.name }}
        {% else %}
            ERROR: file not found
        {% endif %}
    {% endif %}
    &nbsp;<i class="fa fa-external-link"></i>
</a>

Use the value of the parameters.yaml for the listener:

services:
    avtonom.media_storage_client.listener:
        class: Avtonom\MediaStorageClientBundle\EventListener\ObjectAddFileListener
        ...
        tags:
            - { name: doctrine.event_listener, event: prePersist, method: run }
            - { name: doctrine.event_listener, event: preUpdate, method: run }

Use alternative number 1: button to upload the file

<div class="btn-group fileupload-buttonbar" role="group" aria-label="" style="display: inline-flex;">
    <span class="btn btn-primary btn-xs fileinput-button">
        {{ mediaReferenceFull is empty ? 'Add' : 'Update' }}
        &nbsp;<i class="glyphicon glyphicon-pencil"></i>
        <input type="file" name="file"
               class="file-upload fileinput-button"
               data-url="{{ url }}"
        >
    </span>
    <button type="button" class="btn btn-danger btn-xs update-button-clear delete" role="button" title="Clear" data-url="{{ url }}"><i class="fa fa-trash-o"></i></button>
</div>

Processing in the controller:

public function updateAction(Request $request)
{
    /** @var UploadedFile $file */
    $file = $request->files->get('file');
    if($file instanceof UploadedFile){
    
        $proxyMedia = $this->get('avtonom.media_storage_client.manager')->sendFile($file, $clientName, $context);
    
        return new JsonResponse([
            'media' => $proxyMedia->toArray(),
        ]);
    }
}
    

avtonom/media-storage-client-bundle 适用场景与选型建议

avtonom/media-storage-client-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 313 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Symfony2」 「storage」 「bundle」 「SonataMediaBundle」 「SonataMediaBundleClient」 「MediaStorage」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 avtonom/media-storage-client-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 avtonom/media-storage-client-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 313
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-20