Installation:
composer require defrag/plupload-bundle:dev-master
Add to AppKernel.php:
new Defrag\PluploadBundle\DefragPluploadBundle(),
Basic Configuration (config.yml):
defrag_plupload:
upload_service: your.upload_service_id # Must implement `UploaderInterface`
orm_class: Your\Bundle\Entity\YourEntity
First Use Case:
Symfony\Component\Form\AbstractType.plupload field:
$builder->add('assets', 'plupload');
upload_service handles file processing (e.g., saving to disk/S3).Form Handling:
plupload field in forms for drag-and-drop/multiple uploads.use Defrag\PluploadBundle\Form\Type\PluploadType;
class YourFormType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('files', PluploadType::class, [
'label' => 'Upload Files',
'upload_service' => 'your.service_id', // Override config if needed
]);
}
}
Custom Upload Logic:
UploaderInterface for your service:
use Defrag\PluploadBundle\Mode\UploaderInterface;
class YourUploader implements UploaderInterface {
public function upload(array $files) { /* Handle files */ }
}
services.yml:
your.upload_service:
class: Your\Uploader
tags: ['defrag_plupload.uploader']
Twig Integration:
{{ defrag_plupload_js() }}
{{ defrag_plupload_css() }}
Resources/public/js/plupload.js for defaults).Entity Association:
orm_class to auto-associate uploaded files with entities (e.g., Asset)./**
* @ORM\Entity
*/
class Asset {
// Fields for file metadata (e.g., path, name)
}
Symfony Version Lock:
composer.json for symfony/* version constraints.UploaderInterface Strictness:
upload_service must implement UploaderInterface exactly. Missing methods (e.g., upload()) will fail silently or throw errors.php bin/console debug:container your.upload_service
File Validation:
UploaderInterface implementation or via Symfony validators:
$builder->add('assets', PluploadType::class, [
'constraints' => [
new File\FileType(['mime_types' => ['image/jpeg']]),
new File\MaxSize('1024k'),
],
]);
ORM Integration Quirks:
orm_class is set but the entity lacks required fields (e.g., path, name), uploads may succeed but associations will fail.class Asset {
/** @ORM\Column(type="string") */
private $path;
/** @ORM\Column(type="string") */
private $name;
}
JavaScript Conflicts:
Resources/views or use custom JS:
$('#your-plupload-container').pluploadQueue({
// Custom config
});
Check Upload Events:
UploadFile and Error. Listen in JS:
$('#plupload-container').bind('Error', function(up, err) {
console.error('Upload error:', err);
});
Log Upload Service Calls:
UploaderInterface service to log inputs/outputs:
your.upload_service:
class: Your\Uploader
decorates: your.upload_service
arguments: ['@your.upload_service.inner']
Verify File Paths:
file_exists() or Storage components to confirm files are saved:
if (!file_exists($filePath)) {
throw new \RuntimeException("File not saved: $filePath");
}
Custom Templates:
Resources/views to your bundle and extending:
{# app/Resources/DefragPluploadBundle/views/Type/plupload.html.twig #}
{% extends 'DefragPluploadBundle:Type:plupload.html.twig' %}
Dynamic Config:
PluploadType:
$builder->add('assets', PluploadType::class, [
'upload_service' => 'dynamic.service',
'options' => [
'max_file_size' => '5mb',
'multipart' => true,
],
]);
Chunked Uploads:
chunk_size in JS or via options:
chunk_size: '1mb',
upload_chunk_size: '1mb',
How can I help you explore Laravel packages today?