2017 © Pedro Peláez
 

library file-upload-bundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

image

sidus/file-upload-bundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

  • Friday, May 25, 2018
  • by VincentChalnot
  • Repository
  • 1 Watchers
  • 1 Stars
  • 4,328 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 12 Versions
  • 19 % Grown

The README.md

Sidus/FileUploadBundle

This bundle allows you to define Doctrine entities linked to a virtual filesystem entry through the Flysystem storage layer., (*1)

This means that when uploading a file, it will automatically create a corresponding entity in your database matching your resource type., (*2)

WARNING: These entities are meant to be associated to other Doctrine entities, not really managed by themselves: If you want to add a title and a description to a file, create a different entity and create an association to the resource., (*3)

The upload part is handled by the Oneup Uploader Bundle with very little magic added to it., (*4)

This documentation is a work in progress, the bundle is working as is but might require more configuration than what is explained here., (*5)

Installation

You will need to include jQuery in your project on your own., (*6)

$ composer require sidus/file-upload-bundle

Update your Kernel:, (*7)

<?php

class AppKernel
{
    /**
     * {@inheritdoc}
     */
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Oneup\UploaderBundle\OneupUploaderBundle(),
            new Oneup\FlysystemBundle\OneupFlysystemBundle(),
            new Sidus\FileUploadBundle\SidusFileUploadBundle(),
            // ...
        ];
        // ...
    }
}

Note: The order is very important because we override some parameters frop Oneup., (*8)

Additional configuration in your composer.json to expose the jquery-fileupload vendor in public directory of this bundle., (*9)

{
    "scripts": {
        "symfony-scripts": [
            // Append this before the clear-cache script
            "Sidus\\FileUploadBundle\\Composer\\ScriptHandler::symlinkJQueryFileUpload"
        ]
    }
}

Configuration example for OneUploader using Flysystem with local filesystem., (*10)

Note that in order for Sidus/FileUpload to work, the keys for the OneUploader, Flysystem and Sidus must match., (*11)

# one uploader
oneup_uploader:
    mappings:
        document:
            frontend: blueimp
            storage:
                type: flysystem
                filesystem: oneup_flysystem.document_filesystem
            max_size: 64000000

oneup_flysystem:
    adapters:
        my_adapter:
            local:
                directory: '%kernel.root_dir%/../var/data/resources'
    filesystems:
        document:
            adapter: my_adapter

Note the reference in Oneup Uploader to the Flysystem filesystem :, (*12)

document -> oneup_flysystem.document_filesystem, (*13)

Now define your uploadable entities, being careful with the configuration keys, (*14)

sidus_file_upload:
    configurations:
        document: # This key will be the entrypoint to any fileupload form widget
            entity: MyNamespace\AssetBundle\Entity\Document
            filesystem: document # Optional, defaults to configuration key
            uploader: document # Optional, defaults to configuration key

Add the upload routes to your routing:, (*15)

sidus_file_upload:
    resource: "@SidusFileUploadBundle/Resources/config/routing.yml"

Minimum requirements for your entity, (*16)

<?php

namespace MyNamespace\AssetBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Sidus\FileUploadBundle\Entity\Resource;

/**
 * @ORM\Entity(repositoryClass="Sidus\FileUploadBundle\Entity\ResourceRepository")
 */
class Document extends Resource
{
    /**
     * @return string
     */
    public static function getType()
    {
        return 'document'; // Must match your mapping key
    }
}

Load the necessary CSS and JS in your layout (there are many way to do this), (*17)

'bundles/sidusfileupload/css/fileupload.css'

'bundles/sidusfileupload/vendor/jquery-file-upload/js/jquery.fileupload.js'
'bundles/sidusfileupload/vendor/jquery-file-upload/js/jquery.fileupload-jquery-ui.js'
'bundles/sidusfileupload/vendor/jquery-file-upload/js/jquery.iframe-transport.js'
'bundles/sidusfileupload/js/jquery.fileupload.sidus.js'

To load the widget on document initialization (not exactly the proper way to do it...), (*18)

$(document).find('.fileupload-widget').each(function () {
    $(this).sidusFileUpload();
});

When creating a form, you can simply use the "sidus_resource" type to declare the field as an upload. You will only require to set the "resource_type" options corresponding to the entity you want to use., (*19)

Serializer

If you want the Symfony serializer support, you also need to require this:, (*20)

$ composer require sidus/base-serializer-bundle

You need to enable these bundles in your kernel:, (*21)

<?php

class AppKernel
{
    /**
     * {@inheritdoc}
     */
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Sidus\BaseBundle\SidusBaseBundle(),
            new Sidus\BaseSerializerBundle\SidusBaseSerializerBundle(),
            // Then the one documented in the install process
            new Oneup\UploaderBundle\OneupUploaderBundle(),
            new Oneup\FlysystemBundle\OneupFlysystemBundle(),
            new Sidus\FileUploadBundle\SidusFileUploadBundle(),
            // ...
        ];
        // ...
    }
}

And last, you need to enable serializer support in the configuration:, (*22)

sidus_file_upload:
    enable_serializer: true

The Versions

25/05 2018

dev-v1.2.x-dev

dev-v1.2.x-dev https://github.com/VincentChalnot/SidusFileUploadBundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

  Sources   Download

GPL-2.0

The Requires

 

doctrine upload uploader

25/05 2018
23/03 2018
27/06 2017

dev-master

9999999-dev https://github.com/VincentChalnot/SidusFileUploadBundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

  Sources   Download

GPL-2.0

The Requires

 

doctrine upload uploader

22/06 2017

dev-v1.1.x-dev

dev-v1.1.x-dev https://github.com/VincentChalnot/SidusFileUploadBundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

  Sources   Download

GPL-2.0

The Requires

 

doctrine upload uploader

22/06 2017

v1.1.2

1.1.2.0 https://github.com/VincentChalnot/SidusFileUploadBundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

  Sources   Download

GPL-2.0

The Requires

 

doctrine upload uploader

22/06 2017
20/06 2017

v1.1.1

1.1.1.0 https://github.com/VincentChalnot/SidusFileUploadBundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

  Sources   Download

GPL-2.0

The Requires

 

doctrine upload uploader

12/05 2017
09/05 2017

dev-flysystem-migration

dev-flysystem-migration https://github.com/VincentChalnot/SidusFileUploadBundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

  Sources   Download

GPL-2.0

The Requires

 

doctrine upload uploader

08/09 2016

v1.1.0

1.1.0.0 https://github.com/VincentChalnot/SidusFileUploadBundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

  Sources   Download

GPL-2.0

The Requires

 

doctrine upload uploader

30/03 2016

v1.0

1.0.0.0 https://github.com/VincentChalnot/SidusFileUploadBundle

Allow to upload files directly in Doctrine entities, based on oneup/uploader-bundle and jQuery-file-upload

  Sources   Download

GPL-2.0

The Requires

 

doctrine upload uploader