The WebridgeLargeFileBundle for Symfony2 adds support for handling asynchronous upload of large files. At the moment, it simply adds a progress bar during file upload.
- OneupUploaderBundle (https://github.com/1up-lab/OneupUploaderBundle)
- JQuery file upload (https://github.com/blueimp/jQuery-File-Upload)
- Add the bundles to the kernel
new Oneup\UploaderBundle\OneupUploaderBundle(),
new Webridge\LargeFileBundle\WebridgeLargeFileBundle(),- Import the bundle routes in routing.yml
webridge_largefile:
resource: "@WebridgeLargeFileBundle/Resources/config/routing.yml"
prefix: /- Configure the OneupUploaderBundle mappings
eg:
oneup_uploader:
mappings:
video:
allowed_mimetypes: ["video/mp4"]
max_size: 47063040
storage:
directory: uploads%upload_video_rel_directory%-
Add WebridgeLargeFileBundle to assetic's bundles
-
Add the following assetic assets alias:
fileupload:
inputs:
- '../vendor/blueimp/jquery-file-upload/js/vendor/jquery.ui.widget.js'
- '../vendor/blueimp/jquery-file-upload/js/jquery.iframe-transport.js'
- '../vendor/blueimp/jquery-file-upload/js/jquery.fileupload.js'Add a field of type largefile to your form
$builder
->add(
'videoFile',
'largefile',
[
'label' => 'Upload Videos',
'media' => 'video',
'mimeTypesMessage' => "Upload only mp4",
'maxSizeMessage' => "Maximum size is 40 MB",
'previewContainerId' => "previewVideo",
],
)The field will be displayed as an input file styled as a button using bootstrap classes
label: Label of the buttonmedia: refers to the mapping in OneupUploaderBundle's configurationmimeTypesMessage: Localized error message to display for incorrect mime type inputmaxSizeMessage: Localized error message to display if upload file is larger than the maximum size allowedpreviewContainerId: Optional. Id of the video tag container which source will be updated upon upload
The bundle will add two extra hidden fields to the form:
- a field with the name of the file field appended with the string "Name" (eg: videoFileName).
- a field with the name of the file field appended with the string "OriginalName" (eg: videoOriginalFileName). These fields can be used by the application to link the uploaded filename with an entity.